Repository navigation
perf: avoid extra metadata copies when packing - #95
Merged
Merged
Conversation
Metadata serialization copied the raw metadata into a std::string and then zero-filled a worst-case-sized destination before compressing. For a ~96k-file tree that is ~29 MiB raw and ~7 MiB compressed, so pack peak RSS held two to three metadata copies and ended ~4-9% above v1.1.1 (#93). Write meta_buffer directly when compression is disabled or does not shrink, and compress into an uninitialized raw buffer so only the compressed output pages are touched. Pack peak RSS returns to the v1.1.1 level on the release dataset while the archive bytes are unchanged. Refs #93
blocksmith314
commented
Nov 22, 2026
blocksmith314
left a comment
Owner
Author
There was a problem hiding this comment.
Review
LGTM. The change removes both avoidable metadata copies correctly:
- compression disabled:
stored_metadatapoints atmeta_buffer; no copy - compression enabled and smaller: output goes into an uninitialized
make_unique_for_overwritebuffer, and only the compressed bytes are written - compression not shrinking / failing: falls back to the raw
meta_bufferafter releasing the scratch buffer - lifetime is safe: both
meta_bufferandcompressed_metaoutlive the synchronousRandomWrite
The bytes written are the same as before; the header sizes/types/checksum are still set before the write.
Verified locally: Release ctest 177/177, ASan ctest 177/177, CI 5/5 green.
Minor suggestions, not blocking:
- A regression test that packs the same fixture through both the compressed and fallback paths and compares the stored metadata bytes/round-trip would pin the "archive bytes unchanged" claim.
- The benchmark row records
afdeb6bwhile the docs commit isabb42c8; that is fine, just noting the table references the code commit.
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
stored_meta = meta_buffercopy and the zero-filled worst-casestd::stringused as the metadata compression destination.meta_bufferdirectly when compression is disabled or does not shrink.Root cause
On the release dataset the metadata is ~28.9 MB raw and ~7.0 MB compressed (LZ4 4.11x). The old code held the raw metadata, a full copy, and a zero-filled worst-case buffer at the same time; v1.1.1 held only one metadata buffer. This explains the ~4-9% pack peak-RSS drift reported in #93.
Tests
ctest: 177/177 passedctest: 177/177 passedPerformance
Closes #93