Repository navigation
Description
From 4.17.1 on, scalar functions over 100,000 rows take twice as long on Bun. Node does not change.
The code that runs
test/performance/bench.js, case scalar functions 100k. The benchmark data builds these rows once:
const rows = []; // 100,000 rows
for (let i = 0; i < 100000; i++)
rows.push({id: i, a: i % 97, b: 'k' + (i % 50), c: i * 1.5, s: 'str' + (i % 1000)});
const small = []; // 50 rows
for (let i = 0; i < 50; i++) small.push({b: 'k' + i, name: 'name' + i});Each round runs this 5 times, and the median of 5 rounds is reported:
alasql('SELECT UPPER(b) || a AS x FROM ?', [rows]);Per row, the compiled SELECT function calls UPPER and the string concatenation, and builds one result object.
The numbers
Bun 1.4.3 and Node 22.23.3 on an Apple M1 Pro. Each value is the median of 5 separate runs of bench.js; the spread is (max - min) / median across those runs. Source: test/performance/historical/ (#2733).
| 4.16.0 | 4.17.0 | 4.17.1 | 4.17.2 | develop (787cb25) | |
|---|---|---|---|---|---|
| Bun | 10.8 ms | 10.1 ms (spread 113%) | 20.7 ms | 20.7 ms | 20.5 ms |
| Node | 16.9 ms | 16.6 ms | 16.7 ms | 17.0 ms | 17.2 ms |
4.17.0 on Bun has a spread of 113%: some of its 5 runs were already at the slow speed. From 4.17.1 on, every run is slow, and develop still is. Earlier releases show the same switching (0.3.1, 0.3.2, 0.4.6 to 0.4.11), so the case seems to sit on an edge in how JavaScriptCore optimizes this code, and 4.17.1 pushed it over for good.
What changed between 4.17.0 and 4.17.1
One source change: #2395 (5001ffd, "Fix UNION (ALL) for parenthesis SELECT to support ORDER BY and LIMIT"). It adds 47 lines to queryfn3 in src/38query.js, which runs for every SELECT: a .some() over the four set-operation functions to see if a branch has ORDER BY or LIMIT, and a block that sorts and limits the first branch when it does. It also adds grammar rules to src/alasqlparser.jison, so the generated parser changed. The other 26 commits in the range update dependencies and CI actions.
The same release slowed three cases on Bun and none on Node: the tiny query with a cache hit (#2736), scalar functions (#2737) and the WHERE filter (#2738). They probably share one cause.
Please dive in
Find exactly what makes this difference, and why only on Bun (JavaScriptCore). For example: revert parts of #2395 on top of 4.17.1 and measure, or profile both builds with Bun. Write down what you find here, even if the answer is "no fix possible".
Reproduce
npm pack [email protected] [email protected]
mkdir a b && tar xzf alasql-4.17.0.tgz -C a && tar xzf alasql-4.17.1.tgz -C b
bun test/performance/bench.js a/package/dist/alasql.fs.js
bun test/performance/bench.js b/package/dist/alasql.fs.jsRun each build a few times: on Bun a single run can land on either speed.
Activity