api: cap Get result capacity to lower retained heap#834
api: cap Get result capacity to lower retained heap#834snissn wants to merge 5 commits intopr/valuelog-decode-scratch-holder-poolfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR tightens TreeDB’s Get ownership boundary by ensuring returned []byte slices are capacity-cipped to their length, preventing callers from accidentally retaining append-growth headroom and inflating retained heap.
Changes:
- Cap
tree.Tree.Getreturn slice capacity tolen(out)via full-slice expression. - Apply the same capacity capping behavior to cached
caching.Snapshot.Get. - Strengthen
TestGet_SafeCopyto assertcap(result) == len(result)forGet.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
TreeDB/tree/tree.go |
Caps Tree.Get return capacity to prevent retaining excess backing array capacity. |
TreeDB/caching/snapshot.go |
Caps Snapshot.Get return capacity for consistent safe-copy semantics in cached snapshots. |
TreeDB/api_alloc_test.go |
Adds assertions that Get returns a slice with cap == len. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent Get APIs from returning []byte values with extra capacity, so callers don’t accidentally retain or reuse append headroom across an ownership boundary.
Changes:
- Cap the returned slice capacity in
tree.Tree.Gettolen(out)via a full-slice expression. - Apply the same capacity-capping behavior in
caching.Snapshot.Get. - Strengthen
TestGet_SafeCopyto assertcap(result) == len(result)forDB.Get.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| TreeDB/tree/tree.go | Caps Tree.Get return slice capacity to length and documents rationale. |
| TreeDB/caching/snapshot.go | Wraps Snapshot.Get to cap capacity after calling GetAppend. |
| TreeDB/api_alloc_test.go | Adds assertions that Get returns a slice with cap==len. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Pull request overview
Caps Get return slice capacity to its length so callers don’t retain append-growth headroom and unintentionally pin large backing arrays, reducing retained heap/RSS.
Changes:
- Cap
Tree.Get’s returned[]bytecapacity tolen(out)using full slice expressions. - Apply the same capacity-capping behavior to
Snapshot.Get. - Strengthen
TestGet_SafeCopyto assertcap(result) == len(result)forGet.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| TreeDB/tree/tree.go | Caps Tree.Get return slice capacity to length to avoid retaining excess backing array capacity. |
| TreeDB/caching/snapshot.go | Updates Snapshot.Get to cap returned slice capacity similarly (with explicit error handling). |
| TreeDB/api_alloc_test.go | Adds assertions ensuring Get results are capacity-capped to length. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 606d9954b9
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Summary
Why
Get is an ownership boundary. Returning extra capacity can accidentally pin oversized backing arrays and inflate retained heap/RSS under heavy read/reuse patterns.
Validation