Remove the per-item heap allocation from Accumulator::add - #12
Open
JSKitty wants to merge 1 commit into
Open
Conversation
`add` is called once per item while sealing a storage, so building a
100,000-item client store performed 100,000 heap allocations. Each one was
a 32-byte `Vec` holding four `u64` lanes, copied over `self.buf` and freed
immediately.
Write each lane straight back into `self.buf` and track the carry with
`overflowing_add` instead. The arithmetic is the same four-lane
little-endian addition; only the scratch buffer and the `Wrapping`
comparisons around it are gone.
Measured on a 100,000-item client store reconciling against a 110,000-item
relay, best of 25 runs:
client build and reconcile 2345 us -> 650 us
full exchange 4617 us -> 846 us
allocations 107,033 -> 620
Peak memory is unchanged: the removed allocations were short-lived and
never coexisted.
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.
addis called once per item while sealing a storage, so building a 100,000-item client store performed 100,000 heap allocations. Each one was a 32-byteVecholding fouru64lanes, copied overself.bufand freed immediately.Write each lane straight back into
self.bufand track the carry withoverflowing_addinstead. The arithmetic is the same four-lane little-endian addition; only the scratch buffer and theWrappingcomparisons around it are gone.Measured on a 100,000-item client store reconciling against a 110,000-item relay, best of 25 runs:
make precommitbefore committing