You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JS U32.log2 runs the Base bit search inside numeric folds #1688
U32.log2 still runs its five-step Base search for each element. The JS target has Math.clz32, so a variable-input numeric fold can avoid those calls. Zero must keep its Base answer of 0; values with bit 31 set must not become negative answers.
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
log_sum
100
6.578
1.455
Save this as lib.bend:
import Base
def log_sum.go(xs: List<&2, U32>, acc: Nat) -> Nat:
match xs:
case Nil{}: acc
case Con{h, t}: log_sum.go(t, Nat.add(acc, U32.log2(h)))
def log_sum(xs: List<&2, U32>) -> Nat:
log_sum.go(xs, 0n)
Compile with bun bend2/main.ts lib.bend -o lib.mjs. This driver (bench.mjs, run with bun bench.mjs) reproduces the baseline workload:
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