Skip to content

perf: skip BigInt in blake3 b2Compress counter conversion - #84

Draft
elicwhite wants to merge 1 commit into
perf/track-hash-no-bigintfrom
perf/blake3-skip-bigint
Draft

perf: skip BigInt in blake3 b2Compress counter conversion#84
elicwhite wants to merge 1 commit into
perf/track-hash-no-bigintfrom
perf/blake3-skip-bigint

Conversation

@elicwhite

Copy link
Copy Markdown
Owner

blake3.b2Compress was calling fromBig(BigInt(counter), true) on every
call to split the chunk counter into a (h, l) 32-bit pair. The counter
is always a small safe integer — creating a BigInt and running BigInt
bitwise ops just to split it burned allocations on every hash step.

Inline the split directly:
h = counter >>> 0
l = Math.floor(counter / 4294967296) >>> 0

Output is bit-identical to fromBig(..., true).

Measured on autoresearch-scan (2000 charts, 8 workers, 2-run avg):
previous (S2): 2.67 ms mean (3 runs: 2.634, 2.667, 2.717)
this (S5): 2.59 ms mean (2 runs: 2.620, 2.556)
delta: ~−3 to −6% mean

0 hash mismatches, 442/442 tests green. Patch extends
@noble+hashes+1.8.0.patch with the blake3.js diff.

elicwhite commented Apr 20, 2026

Copy link
Copy Markdown
Owner Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

blake3.b2Compress was calling fromBig(BigInt(counter), true) on every
call to split the chunk counter into a (h, l) 32-bit pair. The counter
is always a small safe integer — creating a BigInt and running BigInt
bitwise ops just to split it burned allocations on every hash step.

Inline the split directly:
  h = counter >>> 0
  l = Math.floor(counter / 4294967296) >>> 0

Output is bit-identical to fromBig(..., true).

Measured on autoresearch-scan (2000 charts, 8 workers, 2-run avg):
  previous (S2): 2.67 ms mean (3 runs: 2.634, 2.667, 2.717)
  this  (S5):    2.59 ms mean (2 runs: 2.620, 2.556)
  delta:         ~−3 to −6% mean

0 hash mismatches, 442/442 tests green. Patch extends
@noble+hashes+1.8.0.patch with the blake3.js diff.
@elicwhite
elicwhite force-pushed the perf/blake3-skip-bigint branch from 998e649 to 5d6932c Compare April 20, 2026 14:37
@elicwhite
elicwhite force-pushed the perf/track-hash-no-bigint branch from cdee272 to 36cdb6d Compare April 20, 2026 14:37
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