Repository navigation
fix(buffer): preserve chunks for pooling after writes - #447
Open
ViktorBystrov72 wants to merge 1 commit into
Open
ViktorBystrov72 wants to merge 1 commit into
ViktorBystrov72 wants to merge 1 commit into
Conversation
Signed-off-by: Виктор Быстров <anatema@bk.ru>
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.
net.Buffers.WriteTomodifies its slice entries. When those entries share the backing array ofBuffer.bufs, the pool-return loop receives nil or shortened slices instead of the original chunks.Copy the completed-chunk descriptors before writing. The chunk data and vectored-write path stay the same, and chunks are still offered back to the pool only after
WriteToreturns. Empty and single-chunk buffers keep the existing path.Fixes #359.
Local microbenchmark, Go 1.23.0 on darwin/arm64, six samples, 16 KiB written to
io.Discard:The measured case trades one small descriptor allocation for reuse of the larger chunks. This is a local result, not a universal performance claim; allocation counts for the empty and 128-byte cases were unchanged.
Validation:
sync.Poolretention across GC.make(generation, tests, benchmarks, and golint),go test -race -count=1 ./..., andgo vet ./...passed.