Repository navigation
ZeroCopyReader: chunk consolidation as a future optimization #74
SeanTAllen
started this conversation in
Research
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
ZeroCopyReader: chunk consolidation as a future optimization
Follow-up from #66 (Zero-copy decoding).
Context
The
ZeroCopyReaderdesign uses multi-chunk storage: chunks are appended as-is, zero-copy reads succeed when the requested range falls within a single chunk, and a copy fallback handles cross-chunk spans. This is the initial implementation approach.The consolidation alternative
Instead of keeping chunks separate, copy all appended data into a single contiguous buffer on
append(). This guarantees everyblock()call can usetrimfor zero-copy — no cross-chunk fallback needed.Tradeoffs
Pros:
block()implementation — no chunk-spanning logic.Cons:
append(), even if the data would have been contiguous anyway.valfreezing pattern:trimneedsval, but appending needs mutability. The buffer must be frozen tovalbefore reads and a new mutable buffer started for subsequent appends. This adds complexity.When to revisit
If profiling shows the cross-chunk copy fallback in multi-chunk mode is hitting frequently enough to affect performance, consolidation becomes worth exploring. Until then, multi-chunk is simpler and avoids the
valfreezing complexity.All reactions