Skip to content

Use native JS paths for Base text, numbers and map keys - #1682

Closed
oxura wants to merge 3 commits into
bendlang:mainfrom
oxura:perf/js-base-text-20261017
Closed

oxura wants to merge 3 commits into
bendlang:mainfrom
oxura:perf/js-base-text-20261017

Conversation

@oxura

@oxura oxura commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Use the existing JS number/string representation instead of the Base call chain. The public APIs stay unchanged. The added Nat predicate intrinsics also emit direct C comparisons; the new number/string/map helpers are JS-only. The original nine text reports (#1673–#1681) and the earlier five additional reports linked below each include a compilable wrapper and a driver.

The walks compare numeric U32 Chars and respect packed non-scalars and astral scalars ending in low DC00; JS UTF-16 lexical order is not substituted. Case conversion and trimming stay ASCII-only. Nat.show retains the quotient-constructor overflow. from_list now reuses the fragment-join helper, with no new walker or empty/singleton array. U32.pow uses wrapping imul and arithmetic halving of its Nat exponent, not 32-bit truncation; log2 keeps zero at zero.

For the additional five, Linux x64/Bun 1.3.13, actual generated exports from main e5527d5 versus this change, seven warmed interleaved rounds including module conversion:

Export/workload Calls Main, ms Native path, ms
String.order 100 72.615 16.056
String.eq 100 69.828 1.499
String.get 100 24.736 4.597
U32.pow 1000 2.604 0.191
U32.log2 in a 4000-element fold 100 6.578 1.455
String.from_list 100 4.492 3.026

These are bounded local workloads, not a general speed guarantee. The earlier nine reports retain their original measurements.

Earlier checks (retained): 16,804 actual before/after and independent-oracle API assertions; first-class references; all 1,024 astral scalars with low DC00; frozen Char lists; numeric bounds and wide exponents. The packed-Char, string-kit, text, read-boundary and new sequence programs passed on emitted Bun and native C; the host-Nat fixture passed on Bun (11 runtime outcomes). Repository gate: 54/54, unchanged caps. No parser, kernel or CHANGELOG edits; no mini-cluster/GPU run claimed.

Fixes #1673.
Fixes #1674.
Fixes #1675.
Fixes #1676.
Fixes #1677.
Fixes #1678.
Fixes #1679.
Fixes #1680.
Fixes #1681.
Fixes #1685.
Fixes #1686.
Fixes #1687.
Fixes #1688.
Fixes #1689.

Five more cases in aa331df: logarithmic Nat.pow, direct Nat boolean comparisons, String.cmp without rebuilding its inputs, Map.bit without rebuilding the key, and the fuel-bounded U32 bit-width worker Map.msb.u. The two list-fold candidates were dropped after checking the maintainer decision on #802; no general continuation-passing change is proposed.

Same machine, generated exports from 0b82c20 versus this head, nine warmed alternating rounds:

Operation Calls per round Before, ms After, ms
Nat.pow, exponent 512–1023 1,000 4.297 0.199
Five Nat predicates, balanced operand cases 5,000,000 169.796 150.430
String.cmp, 256-Char common prefix 100 4.771 0.140
Map.bit, bit 8480 of a 257-Char key 1,000 27.712 2.444
Map.msb.u, varying fuel and U32 values 100,000 10.386 2.859

Map.diff on short keys also improved (14.364 → 11.052 ms/100,000 calls); its separate long-prefix String walk did not. No application-wide speed or physical allocation claim.

Additional checks: 29,042 before/after dictionary oracle assertions, 10,491 arithmetic/string assertions on the final generated module, and 22 actual runtime outcomes across 12 existing/new programs on emitted Bun and native C. These include packed U32 Chars, both returned String.cmp inputs, zero/presence bits, wide Nat positions/fuel, valid largest-base powers and overflow. The host export fixture is JS-only. Repo gate 54/54, unchanged caps; no parser/kernel/CHANGELOG edits and no mini-cluster/GPU qualification claimed.

Fixes #1699.
Fixes #1700.
Fixes #1701.
Fixes #1702.
Fixes #1703.

@oxura oxura changed the title Use native JS paths for Base text operations Use native JS paths for Base text and U32 operations Oct 17, 2026
@oxura

oxura commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

Most of this is JS-only optimization, which doesn’t fit the reference-runtime policy in #1644. Closing it; any C work needs its own measurements and a smaller patch.

@oxura oxura closed this Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment