Skip to content

JS String.order still calls Base helpers for every Char in a long prefix #1685

Closed as not planned

Description

@oxura

Comparing two strings with a long common prefix still walks String.order.go and the Base Char comparison. The JS representation can be walked directly, but the order must be numerical U32 Char order, not UTF-16 lexical order.

I measured actual exported modules on main e5527d5 (2.0.37), Linux x64, Bun 1.3.13. These are medians of seven warmed, interleaved before/after rounds, including normal module conversion.

Export Calls Main, ms Local native path, ms
order 100 72.615 16.056
equal 100 69.828 1.499

Save this as lib.bend:

import Base

def order(a: String, b: String) -> Cmp:
  String.order(a, b)

def equal(a: String, b: String) -> Bool:
  String.eq(a, b)

Compile with bun bend2/main.ts lib.bend -o lib.mjs. This driver (bench.mjs, run with bun bench.mjs) reproduces the baseline workload:

const api = (await import(process.argv[2] ?? './lib.mjs')).default;
const text = ('aB' + String.fromCodePoint(0x10000, 0x1f600)).repeat(600);
const cases = [['order', [text, text + 'x'], 100], ['equal', [text, text], 100]];
let sink;
for (const [name, args, calls] of cases) {
  for (let i = 0; i < (name === 'pow' ? 1000 : 100); i++) sink = api[name](...args);
  const rounds = [];
  for (let r = 0; r < 7; r++) {
    const start = performance.now();
    for (let i = 0; i < calls; i++) sink = api[name](...args);
    rounds.push(performance.now() - start);
  }
  console.log(name, rounds.sort((a, b) => a - b)[3]);
}
console.log('sink:', typeof sink);

The local change passed 16,804 actual API checks, including first-class references, numerical U32 ordering, all 1,024 astral scalars whose low unit is DC00, packed non-scalars, and wide Nat exponents against a modular-integer oracle. The focused boundary program also ran on emitted JS and native C. This is a native-representation optimization, not a change to generic fold stack limits, Base reduction, parser, kernel or caps.

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