Skip to content

Historical performance for ORDER BY with LIMIT on Bun from 3.1.1 to 4.0.0 #2739

Open

Description

@mathiasrw

From 4.0.0 on, ORDER BY with LIMIT over 100,000 rows takes 60 percent longer on Bun. Node got about 8 percent slower.

The code that runs

test/performance/bench.js, case order by limit 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 5 times, and the median of 5 rounds is reported:

alasql('SELECT id, c FROM ? ORDER BY c DESC LIMIT 100', [rows]);

alasql sorts all 100,000 rows with the comparator that compileOrder (src/426orderby.js) generates, then keeps 100.

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. Source: test/performance/historical/ (#2733).

3.0.0 3.1.0 3.1.1 4.0.0 4.0.1 develop (787cb25)
Bun 8.1 ms 8.1 ms 8.0 ms 13.0 ms 13.5 ms 13.5 ms
Node 14.0 ms 14.2 ms 13.9 ms 15.0 ms 14.9 ms 15.3 ms

3.1.1 was published in November 2023 from a maintenance branch, after 4.0.0 (April 2023). 4.0.0 was built on 3.1.0, so the range to look at is v3.1.0..v4.0.0.

What changed between 3.1.0 and 4.0.0

Two source commits:

A first measurement

The same query on Bun, with alasql.options.valueof set before the first call, and a different column alias for each setting so the cached statement is not reused:

Build valueof: true valueof: false
3.1.0 4.5 ms 4.2 ms
4.0.0 9.2 ms 4.4 ms
develop 9.1 to 9.8 ms 4.2 ms

(The absolute numbers are lower than in bench.js, which runs other cases before this one.) So on Bun the whole step seems to come from valueof: true. On Node the same test does not show a clear difference: the numbers depend on which setting runs first.

Please dive in

Find exactly what makes this difference. Is it the .valueOf() calls themselves, or how JavaScriptCore optimizes the generated comparator when they are there? Why does Node not care? Is .valueOf() needed when the values are already numbers or strings (it matters only for Date objects)? 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-3.1.0.tgz -C a && tar xzf alasql-4.0.0.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

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