Repository navigation
Description
From 4.17.1 on, the WHERE filter over 100,000 rows takes about 50 percent longer on Bun. Node does not change.
The code that runs
test/performance/bench.js, case where filter 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 10 times, and the median of 5 rounds is reported:
alasql('SELECT * FROM ? WHERE a > 50', [rows]);Per row, the compiled WHERE function compares a, and about half of the rows are copied into the result.
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 | 3.37 ms | 3.33 ms | 5.06 ms | 5.13 ms | 5.10 ms |
| Node | 6.76 ms | 6.85 ms | 6.77 ms | 7.02 ms | 6.97 ms |
Unlike the other two cases, 4.17.0 is stable here (spread 4%), so the step is clean. An earlier step in the same case on Bun is in #2740.
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