Skip to content

perf(domain): batch canonical digest writes with bounded buffer - #994

Merged
kaoru0822-kitauji merged 1 commit into
morluto:mainfrom
HoneyTyagii:perf/canonical-digest-batching-904
Oct 7, 2026
Merged

kaoru0822-kitauji merged 1 commit into
morluto:mainfrom
HoneyTyagii:perf/canonical-digest-batching-904

Conversation

@HoneyTyagii

Copy link
Copy Markdown
Contributor

Summary

Closes #904.

Batch small canonical parts before calling crypto hash update, while preserving the exact canonical byte stream and streaming memory bound.

Problem and expected behavior

A native Node CPU profile of analyze-javascript-application dist/server shows about 44.8 percent of sampled frames in hash.update plus emitCanonical:

  • update in node:internal/crypto/hash: 1,053 self samples
  • emitCanonical in dist/domain/canonicalDigest.js: 924 self samples
  • Total 1,977 of 4,409 exported samples

src/domain/canonicalDigest.ts calls emitCanonical(value, part => hash.update(part), ...) where punctuation, keys, and scalars each trigger a separate native crossing. This preserves the streaming bound added after #623 but adds per token overhead.

Expected: same digests with fewer hash updates, no full graph string in memory.

Changes

  • Add bounded buffering in digestCanonicalValue: accumulate emitted parts in a string buffer up to 8 KB, flush with hash.update, flush remainder before digest.
  • Keep emitCanonical recursion, validation, and failure behavior unchanged, including Unicode, sparse arrays, unsupported values, toJSON, invalid numbers, and cycles.
  • Add regression coverage in src/domain/canonicalDigest.test.ts:
    • digest equivalence against canonicalize for existing fixtures
    • update call count drops on a wide object while digest stays identical

Verification

Risk

Low. Byte stream is unchanged, only grouping of hash writes changes. Failure paths and digest mismatch errors stay the same. Related: #623, #723.

Copilot AI balanced review requested due to automatic review settings October 7, 2026 15:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@kaoru0822-kitauji
kaoru0822-kitauji merged commit c675305 into morluto:main Oct 7, 2026
22 checks passed
@morluto

morluto commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Thanks, @HoneyTyagii, for your work on “perf(domain): batch canonical digest writes with bounded buffer.” I appreciate your contribution to REA.

darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
…-batching-904

perf(domain): batch canonical digest writes with bounded buffer
@morluto morluto added performance Performance regressions, scaling limits, and bounded-resource work area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
@morluto morluto added the area: domain Domain logic, errors, and pure functions label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior performance Performance regressions, scaling limits, and bounded-resource work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Investigate bounded batching of canonical digest writes from real CPU profile

4 participants