Skip to content

perf(base): bound the Nat.read length check - #2209

Open
toprameen wants to merge 1 commit into
bendlang:mainfrom
toprameen:bound-nat-read-length-check
Open

toprameen wants to merge 1 commit into
bendlang:mainfrom
toprameen:bound-nat-read-length-check

Conversation

@toprameen

Copy link
Copy Markdown
Contributor

Nat.read now short-circuits its length check when it sees a 16th character after trimming leading zeros. Inputs with exactly 15 characters still compare against the maximum Nat.

In a local benchmark of 100,000 reads of a 128-digit field, native C went from 43 ms to 3 ms, Bun from 36 ms to 31 ms, and Node from 68 ms to 21 ms. Near the cutoff, Bun took 32 ms instead of 17 ms for 100,000 reads of a 16-digit field.

Existing parser fixtures pass, and BendTT verifies that the old and new readers return the same result for every String.

@toprameen
toprameen marked this pull request as ready for review November 19, 2026 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant