[Memory Optimization] Right-size data stream filter buffers - #13
Open
Arcticae wants to merge 1 commit into
Open
Conversation
Arcticae
force-pushed
the
task/004-right-size-filter-buffers
branch
from
August 26, 2026 11:00
3101cd8 to
4573079
Compare
Arcticae
force-pushed
the
task/004-right-size-filter-buffers
branch
from
August 26, 2026 13:30
4573079 to
b216eb5
Compare
Arcticae
marked this pull request as ready for review
August 26, 2026 13:42
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
Replace the unconditional 1 MiB reservation in every
DataStream::filter_fragmentpass with an exact, checked protobuf encoded-size calculation.The implementation resolves joins and matches, retains the already-fetched header/body data, computes the full output size, allocates once, and encodes with the existing safe Prost helpers. It preserves one output
Bytesvalue per block filter, including empty outputs.Motivation
DHAT identified the fixed reservation as the dominant allocation pattern:
Most filtered responses are substantially smaller than 1 MiB. Repeating this reservation creates allocator traffic and slack that can amplify fragmentation and transparent-huge-page retention even when Rust ownership is bounded.
Implementation
BytesMutonly after the header decision and all matches are known.DEFAULT_BLOCKS_BUFFER_SIZEand the fixed 1 MiB reservation.Behavior preserved
Tests
Tests were established before the implementation and initially failed on the missing sizing/encoding helpers.
Coverage includes:
Validation run:
cargo test -p apibara-dna-common --lib— 8 passed;cargo check -p apibara-dna-common;cargo fmt --all -- --check;git diff --check origin/main...HEAD;The full integration suite was also attempted on
main, but its existing container fixture cannot pullbitnami/etcd:latest(manifest unknown). The task-specific library tests and compilation pass. Nix was unavailable on the implementation host.Review and experiment notes
This PR is based directly on
mainand is independent from the Foyer-budget and response-queue PRs. The three task branches are siblings, not a stack.Still required before production rollout: