-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(chunker): reduce overall memory use #649
Conversation
When the chunker is not able to fill a chunk with data, it allocated a new buffer for the partial chunk of data. With many files this results in allocation of many small buffers of varying sizes, leading to heap fragmentation. This PR allocates a new buffer from the pool only if doing so would save space, otherwise it uses an partially filled (over-allocated) chunk. This makes all chunker allocation sizes be powers of 2. Heap fragmentation is reduced at the cost of some temporary over-allocation. The advantage is that the overallocation is much shorter lived than the heap fragmentation.
Codecov ReportAttention: Patch coverage is
@@ Coverage Diff @@
## main #649 +/- ##
==========================================
+ Coverage 59.89% 59.92% +0.02%
==========================================
Files 237 237
Lines 29955 29972 +17
==========================================
+ Hits 17942 17960 +18
+ Misses 10398 10396 -2
- Partials 1615 1616 +1
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Smoke-tested in ipfs/kubo#10485 as well, lgtm.
Let's see how it behaves in kubo 0.30.0-rc1
* chore: go-ipfs-cmds v0.12.0 https://github.com/ipfs/go-ipfs-cmds/releases/tag/v0.12.0 * chore: boxo main with boxo#649 ipfs/boxo#649
When the chunker is not able to fill a chunk with data, it allocated a new buffer for the partial chunk of data. With many files this results in allocation of many small buffers of varying sizes, leading to heap fragmentation. This PR allocates a new buffer from the pool only if doing so would save space, otherwise it uses an partially filled (over-allocated) chunk. This makes all chunker allocation sizes be powers of 2.
Heap fragmentation is reduced at the cost of some temporary over-allocation. The advantage is that the overallocation is much shorter lived than the heap fragmentation.
Possible fix for issue #647