Skip to content

perf(codec): reuse one padding buffer when decoding a block - #9895

Open
g4lb wants to merge 1 commit into
dgraph-io:mainfrom
g4lb:perf/codec-pad
Open

g4lb wants to merge 1 commit into
dgraph-io:mainfrom
g4lb:perf/codec-pad

Conversation

@g4lb

@g4lb g4lb commented Nov 21, 2026 •

Copy link
Copy Markdown

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.

See it in action
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.

@g4lb
g4lb requested a review from a team as a code owner November 21, 2026 18:01
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Explain Change →

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.

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Refactor

Suggested labels: go

Suggested reviewers: manishrjain, shiva-istari, mlwelles

Merge Risk: Minimal · up to 8b3b9

This change reduces allocations when decoding compressed UID blocks without changing the decoded output. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant