-
Notifications
You must be signed in to change notification settings - Fork 4.1k
perf: less alloc #25360
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
perf: less alloc #25360
Conversation
📝 WalkthroughWalkthroughRefactors int64SliceToBytes in store/pruning/manager.go to preallocate the exact output byte slice and write each int64’s big-endian bytes directly at computed offsets, replacing per-element append-based construction. No public APIs changed; behavior remains the same. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
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. Comment |
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
store/pruning/manager.go (2)
227-231
: Allocation-free encoding is correct; minor readability tweak suggestedChange reduces allocations and keeps endianness consistent. Consider making the 8‑byte window explicit and using multiplication for clarity.
func int64SliceToBytes(slice ...int64) []byte { - bz := make([]byte, len(slice)*8) - for i, ph := range slice { - binary.BigEndian.PutUint64(bz[i<<3:], uint64(ph)) - } + bz := make([]byte, len(slice)*8) + for i, ph := range slice { + off := i * 8 // clearer than i<<3 + binary.BigEndian.PutUint64(bz[off:off+8], uint64(ph)) + } return bz }
226-231
: Add int64ToBytes(int64) and use it from storePruningSnapshotHeightImplement a helper that encodes a single int64 (no variadic allocation) and call it from store/pruning/manager.go (storePruningSnapshotHeight — currently calls int64SliceToBytes at line 199); keep int64SliceToBytes(...) for multi-value callers (store/pruning/manager_test.go at line 439).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Knowledge base: Disabled due to Reviews -> Disable Knowledge Base
setting
📒 Files selected for processing (1)
store/pruning/manager.go
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Summary
is there a test that validates this change is ok? |
here will test. cosmos-sdk/store/pruning/manager_test.go Line 439 in 97c0bd8
and this test pass. |
@aljo242 can you help with the gosec check failed. I do not understand the failed log. |
Can you unit test this and add a benchmark function for this? |
done @aljo242 |
@technicallyty for the final approval here |
@aljo242 Done |
gentle ping! |
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.
lgtm, thanks!
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #25360 +/- ##
=======================================
Coverage 52.87% 52.88%
=======================================
Files 797 797
Lines 64903 64903
=======================================
+ Hits 34318 34321 +3
+ Misses 30585 30582 -3 🚀 New features to boost your workflow:
|
Summary by CodeRabbit