Skip to content

perf: avoid BigInt alloc in calculateTrackHash binary layout - #83

Draft
elicwhite wants to merge 1 commit into
perf/blake-inline-mixingfrom
perf/track-hash-no-bigint
Draft

perf: avoid BigInt alloc in calculateTrackHash binary layout#83
elicwhite wants to merge 1 commit into
perf/blake-inline-mixingfrom
perf/track-hash-no-bigint

Conversation

@elicwhite

Copy link
Copy Markdown
Owner

DataView.setBigInt64 forces a BigInt argument. In calculateTrackHash,
every tick and length — per tempo, time signature, star power, solo
section, flex lane, freestyle section, and note — allocated a new
BigInt object. For a dense track with 10k notes that's ~20k BigInt
allocations per track hash, feeding GC.

Charts are bounded: no tick or length approaches 2^31, let alone 2^63.
Replace each setBigInt64(i, BigInt(x), true) with a local helper
that writes two unsigned 32-bit LE words (low = x, high = 0). Output
is byte-identical — BigInt(x) for any non-negative int32 produces the
same 8-byte little-endian layout.

Measured on autoresearch-scan (2000 charts, 8 workers, 3-run avg):
previous: 2.80 ms mean (runs: 2.730, 2.876, 2.876)
this: 2.67 ms mean (runs: 2.634, 2.667, 2.717)
delta: −4.5% mean, max tail steady around 15-24 ms

0 hash mismatches across all runs, 442/442 tests green.

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.

DataView.setBigInt64 forces a BigInt argument. In calculateTrackHash,
every tick and length — per tempo, time signature, star power, solo
section, flex lane, freestyle section, and note — allocated a new
BigInt object. For a dense track with 10k notes that's ~20k BigInt
allocations per track hash, feeding GC.

Charts are bounded: no tick or length approaches 2^31, let alone 2^63.
Replace each `setBigInt64(i, BigInt(x), true)` with a local helper
that writes two unsigned 32-bit LE words (low = x, high = 0). Output
is byte-identical — BigInt(x) for any non-negative int32 produces the
same 8-byte little-endian layout.

Measured on autoresearch-scan (2000 charts, 8 workers, 3-run avg):
  previous: 2.80 ms mean (runs: 2.730, 2.876, 2.876)
  this:     2.67 ms mean (runs: 2.634, 2.667, 2.717)
  delta:    −4.5% mean, max tail steady around 15-24 ms

0 hash mismatches across all runs, 442/442 tests green.
@elicwhite
elicwhite force-pushed the perf/blake-inline-mixing branch from c64d521 to 6cde23e 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