Skip to content

feat(server): implement TwoHalves buffer#2944

Merged
numinnex merged 17 commits intomasterfrom
two_halves
Mar 20, 2026
Merged

feat(server): implement TwoHalves buffer#2944
numinnex merged 17 commits intomasterfrom
two_halves

Conversation

@numinnex
Copy link
Contributor

This PR introduces an TwoHalves buffer, that uses Vec<u8> instead of Bytes as it's underlying storage.

TwoHalves splits the underlying storage into two parts (mutable and non-mutable one). The non-mutable part uses thread-safe reference counting for cheap sharing (Bytes like), where the mutable one is copied over on each clone.

In the initial state both the mutable and non-mutable parts point to the same allocation using exactly the same control block, the diverge happens on first clone when the mutable part gets copied over and re-allocated entirely.

@codecov
Copy link

codecov bot commented Mar 16, 2026

Codecov Report

❌ Patch coverage is 92.55952% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.86%. Comparing base (f0e8578) to head (69220df).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
core/iobuf/src/lib.rs 92.55% 25 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2944      +/-   ##
============================================
+ Coverage     71.81%   71.86%   +0.05%     
  Complexity      930      930              
============================================
  Files          1116     1117       +1     
  Lines         92616    92952     +336     
  Branches      70139    70484     +345     
============================================
+ Hits          66512    66803     +291     
- Misses        23543    23579      +36     
- Partials       2561     2570       +9     
Flag Coverage Δ
csharp 67.43% <ø> (-0.21%) ⬇️
go 36.38% <ø> (ø)
java 62.08% <ø> (ø)
node 91.37% <ø> (-0.15%) ⬇️
python 81.43% <ø> (ø)
rust 72.60% <92.55%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
core/iobuf/src/lib.rs 92.55% <92.55%> (ø)

... and 13 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hubcio
Copy link
Contributor

hubcio commented Mar 17, 2026

What about using AlignedVec as underlying buffer? this way we should be able to seamlessly switch to direct-io later on. See #2921

@numinnex
Copy link
Contributor Author

What about using AlignedVec as underlying buffer? this way we should be able to seamlessly switch to direct-io later on. See #2921

I am in the process of looking at #2921, the next logical step is to introduce alignment both for the inner allocation, aswell as for the split_at boundry.

@numinnex
Copy link
Contributor Author

I've added at the end of the file an comment with an proposed design for the TwoHalves aswell as Frozen buffer.

I am not sure about the design and the trade-off that is offer, would like to hear your opinions @krishvishal @hubcio

@numinnex
Copy link
Contributor Author

I've decided against using the proposed new design, as it would make using AlignedVec extremely inefficient, requiring large amount of padding between ControlBlock and the data pointer.

@numinnex numinnex merged commit f762e4f into master Mar 20, 2026
139 of 142 checks passed
@numinnex numinnex deleted the two_halves branch March 20, 2026 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants