Skip to content

perf: inline @noble/hashes G1s/G2s into blake2 compress - #82

Draft
elicwhite wants to merge 1 commit into
masterfrom
perf/blake-inline-mixing
Draft

perf: inline @noble/hashes G1s/G2s into blake2 compress#82
elicwhite wants to merge 1 commit into
masterfrom
perf/blake-inline-mixing

Conversation

@elicwhite

Copy link
Copy Markdown
Owner

@noble/hashes uses a pattern where G1s and G2s each return a fresh
{ a, b, c, d } object per call, destructured by the caller inside the
compression loop. In the chart-hasher path this is ~112 object
allocations per compress call (16 G-calls × 7 rounds for blake3),
dominating GC and showing up as 30–35% of scanner CPU time in the
profile.

Inline both G functions directly into compress, writing through the
v0..v15 locals via a scratch t temp. Semantics are byte-identical
to upstream — the inlining only removes the allocation wrapper.

Measured on the scan-perf autoresearch bench (2000 charts, 8 workers):
baseline (tip of perf stack):
mean 6.156 ms, p50 5.299 ms, p95 13.818 ms, p99 20.051 ms, max 33.346 ms
this patch:
mean 2.730 ms, p50 2.223 ms, p95 6.952 ms, p99 10.165 ms, max 16.368 ms
delta: −55.7% mean, −49.7% p95, −50.9% max
(2.26× speedup on scanner)

0 hash mismatches across 2000 charts — byte-identical ScannedChart
output. 442/442 scan-chart tests still green.

The patch is stored at patches/@noble+hashes+1.8.0.patch and applies
via patch-package on install.

elicwhite commented Apr 20, 2026

Copy link
Copy Markdown
Owner Author

@elicwhite
elicwhite changed the base branch from perf/avoid-spread-in-writer to graphite-base/82 April 20, 2026 14:34
@elicwhite
elicwhite force-pushed the perf/blake-inline-mixing branch from bb1eaf6 to c64d521 Compare April 20, 2026 14:34
@elicwhite
elicwhite changed the base branch from graphite-base/82 to master April 20, 2026 14:34
@noble/hashes uses a pattern where G1s and G2s each return a fresh
{ a, b, c, d } object per call, destructured by the caller inside the
compression loop. In the chart-hasher path this is ~112 object
allocations per compress call (16 G-calls × 7 rounds for blake3),
dominating GC and showing up as 30–35% of scanner CPU time in the
profile.

Inline both G functions directly into compress, writing through the
v0..v15 locals via a scratch `t` temp. Semantics are byte-identical
to upstream — the inlining only removes the allocation wrapper.

Measured on the scan-perf autoresearch bench (2000 charts, 8 workers):
  baseline (tip of perf stack):
    mean  6.156 ms, p50  5.299 ms, p95 13.818 ms, p99 20.051 ms, max 33.346 ms
  this patch:
    mean  2.730 ms, p50  2.223 ms, p95  6.952 ms, p99 10.165 ms, max 16.368 ms
  delta: −55.7% mean, −49.7% p95, −50.9% max
  (2.26× speedup on scanner)

0 hash mismatches across 2000 charts — byte-identical ScannedChart
output. 442/442 scan-chart tests still green.

The patch is stored at patches/@noble+hashes+1.8.0.patch and applies
via patch-package on install.
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