Repository navigation
perf(domain): batch canonical digest writes with bounded buffer - #994
Merged
kaoru0822-kitauji merged 1 commit intoOct 7, 2026
Merged
kaoru0822-kitauji merged 1 commit into
kaoru0822-kitauji merged 1 commit into
Conversation
Owner
|
Thanks, @HoneyTyagii, for your work on “perf(domain): batch canonical digest writes with bounded buffer.” I appreciate your contribution to REA. |
This was referenced Oct 8, 2026
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/servershows about 44.8 percent of sampled frames inhash.updateplusemitCanonical:updateinnode:internal/crypto/hash: 1,053 self samplesemitCanonicalindist/domain/canonicalDigest.js: 924 self samplessrc/domain/canonicalDigest.tscallsemitCanonical(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
digestCanonicalValue: accumulate emitted parts in a string buffer up to 8 KB, flush withhash.update, flush remainder beforedigest.emitCanonicalrecursion, validation, and failure behavior unchanged, including Unicode, sparse arrays, unsupported values,toJSON, invalid numbers, and cycles.src/domain/canonicalDigest.test.ts:canonicalizefor existing fixturesVerification
npx vitest run src/domain/canonicalDigest.test.ts: 6 passedcanonicalizefor JSON values and prior edge fixturesdist/serveranalysis with CPU and heap profiles, elapsed samples, and peak RSS before claiming speedupRisk
Low. Byte stream is unchanged, only grouping of hash writes changes. Failure paths and digest mismatch errors stay the same. Related: #623, #723.