You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(codec): reuse one padding buffer when decoding a block - #9895
UnpackBlock made a new 17-byte padding buffer for each of the last groups of every block. Now one array on the stack holds the padding. groupvarint.Decode4 is noescape, so the array does not escape. The decoded UIDs do not change.
Benchmark
Before
After
Allocs
BenchmarkUidPack/decode/128 (1M UIDs)
4.99 ms
4.61 ms
23449 → 10
BenchmarkListIntersectRandom compressed, 1M UIDs
14.57 ms
14.45 ms
~21000 → 10
BenchmarkListIntersectRandom compressed, 10k UIDs
92.5 µs
88.1 µs
~230 → 10
Decode of 2000 UIDs
14.87 µs
14.26 µs
35 → 11
On AMD EPYC 7763 (Go 1.27.4), no benchmark was slower in all 3 code layouts.
Checks:
go test -race ./codec ./algo ./posting passes.
Decode, seek and Next returned the input for 40000 random UID lists.
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.
Summary by CodeRabbit
Performance
Reduced temporary allocations when decoding short blocks.
No actionable comments were generated in the recent review.
Walkthrough
Changes
Decoder.UnpackBlock now copies short encoded delta data into a fixed 17-byte array, clears the unused bytes, and decodes from the array instead of allocating a padding slice.
Changes
Short delta padding
Layer / File(s)
Summary
Fixed-size padding codec/codec.go
UnpackBlock uses a fixed 17-byte array for short encoded data, clears its unused tail, and decodes from the array.
This change reduces allocations when decoding compressed UID blocks without changing the decoded output. No merge-blocking risk was found.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: reusing one padding buffer when decoding a block in the codec package. The raw summary says UnpackBlock now uses one fixed 17-byte padding array instead of allocating …
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: reusing one padding buffer when decoding a block in the codec package. The raw summary says UnpackBlock now uses one fixed 17-byte padding array instead of allocating a new slice for each short group. The PR objectives confirm the goal of reducing allocations in UnpackBlock. The title uses the conventional perf(codec) prefix and is concise, specific, and free of file lists or vague terms.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: 1f6ec820-266a-43a6-91da-39f27430671c
Commits
Reviewing files that changed from the base of the PR and between e95fc26 and 8b3b9f5.
Files selected for processing: 1
codec/codec.go
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
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
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.
UnpackBlockmade a new 17-byte padding buffer for each of the last groups of every block. Now one array on the stack holds the padding.groupvarint.Decode4isnoescape, so the array does not escape. The decoded UIDs do not change.BenchmarkUidPack/decode/128(1M UIDs)BenchmarkListIntersectRandomcompressed, 1M UIDsBenchmarkListIntersectRandomcompressed, 10k UIDsOn AMD EPYC 7763 (Go 1.27.4), no benchmark was slower in all 3 code layouts.
Checks:
go test -race ./codec ./algo ./postingpasses.Decode, seek andNextreturned the input for 40000 random UID lists.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.Summary by CodeRabbit