Repository navigation
Description
From 0.3.2 on, the WHERE filter over 100,000 rows takes about 30 percent longer on Bun. Node does not change. The case stayed at that level until 4.17.1, where it got slower again (#2738).
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)});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).
| 0.3.0 | 0.3.1 | 0.3.2 | 0.3.3 | 4.17.0 | develop (787cb25) | |
|---|---|---|---|---|---|---|
| Bun | 2.73 ms | 2.76 ms | 3.61 ms | 3.63 ms | 3.33 ms | 5.10 ms |
| Node | 6.76 ms | 6.79 ms | 6.86 ms | 6.78 ms | 6.85 ms | 6.97 ms |
The spreads are 5 to 13 percent, so the step is not noise.
What changed between 0.3.1 and 0.3.2
12 source commits, 192 lines added and 98 removed outside the generated parser. The ones that touch how a WHERE expression is compiled:
- cc5074b "(null = null) is null": rewrites 121 lines of
src/50expression.js, which generates the code for comparisons such asa > 50. - 67f54bf "Allow non-reserved keywords as identifiers" (Allow non-reserved keywords as identifiers #745): grammar change that grew the generated parser from 281 KB to 308 KB.
- be2d8a7 "Add stub for ARRAY[] notation": a small grammar change.
- 635bafb "Make string escape sequences SQL compliant" (Make string escape sequences SQL compliant #734): 28 lines in
src/15utility.js.
The rest (CSV/TSV, hasIndexedDB, CLI, INTO and RECORDSET column order, linting) is not on this query's path.
Please dive in
Find exactly what makes this difference. A good start: compare the generated WHERE function of 0.3.1 and 0.3.2 for this query, and measure 0.3.2 with each candidate commit reverted. Write down what you find here, even if the answer is "no fix possible": the code has changed a lot since 2016, so the finding may only explain the history.
Reproduce
npm pack [email protected] [email protected]
mkdir a b && tar xzf alasql-0.3.1.tgz -C a && tar xzf alasql-0.3.2.tgz -C b
bun test/performance/bench.js a/package/dist/alasql.fs.js
bun test/performance/bench.js b/package/dist/alasql.fs.js
Activity