Skip to content

Historical performance for tiny query, cache hit on Bun from 4.17.0 to 4.17.1 #2736

Open

Description

@mathiasrw

From 4.17.1 on, a cached tiny query takes twice as long on Bun. Node does not change.

The code that runs

test/performance/bench.js, case tiny query, cache hit. 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 the same SQL text 2000 times, and the median of 5 rounds is reported:

alasql('SELECT 1 AS v FROM ? WHERE a > 100', [small]);

After the first call, alasql takes the compiled statement from db.sqlCache and only runs it. So this case measures the fixed cost of running a statement: alasql.exec, dexec, the cache lookup, queryfn and queryfn3, on 50 rows.

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 4.4 µs 4.4 µs (spread 107%) 9.3 µs 9.4 µs 9.2 µs
Node 6.0 µs 5.9 µs 6.1 µs 6.2 µs 5.6 µs

4.17.0 on Bun has a spread of 107%: some of its 5 runs were already at the slow speed. From 4.17.1 on, every run is slow, and develop still is.

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.js

Run each build a few times: on Bun a single run can land on either speed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions