perf: pool []queryValues slices to reduce per-request allocations#753
Draft
mykaul wants to merge 2 commits intoscylladb:masterfrom
Draft
perf: pool []queryValues slices to reduce per-request allocations#753mykaul wants to merge 2 commits intoscylladb:masterfrom
mykaul wants to merge 2 commits intoscylladb:masterfrom
Conversation
Author
|
CI failure is a transient issue, will send a separate fix. |
Author
|
There was a problem hiding this comment.
Pull request overview
This PR reduces per-request allocations in the query execution path by pooling []queryValues slices (bucketed by common sizes) and reusing them across executeQuery() and executeBatch() calls.
Changes:
- Add bucketed
sync.Poolhelpers for[]queryValuesallocation/reuse (caps 8/16/32/64/128). - Use the pool in
Conn.executeQuery()/Conn.executeBatch()and return slices after request frame serialization. - Add unit tests and benchmarks covering bucket selection, pooling behavior, and allocation improvements.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
frame.go |
Introduces the bucketed []queryValues pooling helpers (getQueryValues/putQueryValues/putBatchQueryValues). |
conn.go |
Switches query/batch execution to allocate params.values / b.values via the pool and returns them after frame serialization (plus cleanup on errors). |
frame_test.go |
Adds tests for bucket sizing and pooling behavior, plus benchmarks comparing pooled vs make() allocations. |
dd9eae2 to
74f4612
Compare
74f4612 to
d1b7cdb
Compare
d1b7cdb to
d7f412d
Compare
d7f412d to
d43cce5
Compare
Author
|
Addressed the review feedback: Fixed (this push):
Not a bug (Copilot false positive):
Acknowledged but not changing:
|
d43cce5 to
da3e671
Compare
Use bucketed sync.Pool (caps 8/16/32/64/128) to reuse []queryValues slices in executeQuery() and executeBatch(). Slices are returned to the pool immediately after c.exec() serializes the frame, with clear() to release string/[]byte references. Benchmark (8 values, sequential): ~3.9x faster than make(). Benchmark (8 values, parallel): ~7.7x faster than make().
9bb9a9e to
c3c37e9
Compare
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.
Use bucketed sync.Pool (caps 8/16/32/64/128) to reuse []queryValues slices in executeQuery() and executeBatch(). Slices are returned to the pool immediately after c.exec() serializes the frame, with clear() to release string/[]byte references.
Benchmark Results
Benchmark Pool make() Speedup Alloc savings
Sequential (8 values) ~53 ns/op, 27 B ~132 ns/op, 387 B ~2.5x 360 B/op
Parallel (8 values) ~31 ns/op, 27 B ~180 ns/op, 387 B ~5.8x 360 B/op