Repository navigation
perf(interp): pool small structs - #183
Conversation
|
Warning Review limit reached
Next review available in: 15 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThe change adds resettable struct storage and interpreter-owned pooling for small structs. Struct construction paths use the pool-aware helper. Allocation tracking and GC worklist reuse support the lifecycle changes. Benchmark documentation contains refreshed August 2026 measurements. ChangesStruct reuse
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Construction
participant Interpreter
participant Struct
participant GC
Construction->>Interpreter: newStruct(type)
Interpreter->>Struct: Reset(type)
Struct-->>Interpreter: Initialized struct
Interpreter->>GC: Track allocation
GC->>Interpreter: Reclaim small struct
Interpreter->>Interpreter: Return struct to pool
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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.
Actionable comments posted: 1
🧹 Nitpick comments (3)
types/struct_test.go (3)
43-43: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDo not assert the
types.Struct.Datarepresentation.
require.Len(t, s.Data, 2)checks storage layout, not public behavior. Remove it unless the length is a documented public contract.As per coding guidelines: Tests must not access private symbols or representations; assert internal invariants through public observable behavior, generated output, or executable boundaries.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@types/struct_test.go` at line 43, Remove the require.Len assertion on s.Data from the test, and rely on public behavior or generated output assertions instead of checking the internal types.Struct.Data representation.Source: Coding guidelines
36-44: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winGive
types.Struct.Resetits own top-level test.Move this sub-case to
TestStruct_Reset. Keep its scenarios undert.Run.As per coding guidelines:
**/*_test.go: Define one top-level test per public symbol usingTest<Func>orTest<Type>_<Method>, and put sub-cases undert.Runrather than separate parallel top-level tests.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@types/struct_test.go` around lines 36 - 44, Move the “reset clears small storage” scenario from its current parent test into a new top-level TestStruct_Reset function, keeping the scenario wrapped in t.Run. Preserve the existing assertions and setup for types.Struct.Reset unchanged.Source: Coding guidelines
36-44: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover the other
types.Struct.Resetbehaviors.The test covers only the small two-field I32 path. Add sub-cases for a struct with more than four fields and for a reference field. Assert the reset values through
FieldorRaw.As per coding guidelines: Tests must follow
docs/testing.md, cover public specifications and opcode behavior as required, and assert only public observable behavior.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@types/struct_test.go` around lines 36 - 44, Add sub-cases to the existing “reset clears small storage” test for a struct with more than four fields and for a struct containing a reference field, exercising types.Struct.Reset in each case. Assert the post-reset values only through the public Field or Raw APIs, following docs/testing.md and preserving the existing small-storage assertions.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@interp/interp.go`:
- Around line 2352-2362: Update the release traversal around the release
function to use a local worklist for each invocation instead of resetting shared
i.releaseWork, preserving pending outer-sweep entries while recursively
releasing child references. Keep shared worklist manipulation limited to callers
or reclaim, or save and restore it across nested release calls.
---
Nitpick comments:
In `@types/struct_test.go`:
- Line 43: Remove the require.Len assertion on s.Data from the test, and rely on
public behavior or generated output assertions instead of checking the internal
types.Struct.Data representation.
- Around line 36-44: Move the “reset clears small storage” scenario from its
current parent test into a new top-level TestStruct_Reset function, keeping the
scenario wrapped in t.Run. Preserve the existing assertions and setup for
types.Struct.Reset unchanged.
- Around line 36-44: Add sub-cases to the existing “reset clears small storage”
test for a struct with more than four fields and for a struct containing a
reference field, exercising types.Struct.Reset in each case. Assert the
post-reset values only through the public Field or Raw APIs, following
docs/testing.md and preserving the existing small-storage assertions.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: fd6d1391-d094-42c7-9478-bc74aceb455a
📒 Files selected for processing (5)
internal/cmd/geninterp/lower.gointerp/interp.gointerp/threaded.gotypes/struct.gotypes/struct_test.go
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
interp/interp.go (1)
63-63: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winKeep a reusable worklist for GC marking.
At Line 2337,
workstarts as a nil local slice. Whenpushappends the first marked address, the traversal must grow a backing array. This adds allocation pressure on every non-empty mark traversal and removes reusable interpreter worklist storage. Keep a separatemarkWorkfield, reset its length before each traversal, and retain its capacity afterward.Proposed fix
type Interpreter struct { ... work []int + markWork []int } func (i *Interpreter) mark() { - var work []int + work := i.markWork[:0] ... + i.markWork = work[:0] }Also applies to: 2337-2343
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@interp/interp.go` at line 63, Replace the interpreter’s local GC marking worklist with a reusable markWork field. In the marking traversal around push at line 2337, reset markWork to length zero before each traversal, use it for queued addresses, and retain its backing capacity for subsequent traversals; add the field alongside the existing work storage.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/benchmarks.md`:
- Line 74: Update the benchmark summary around the CPython comparison to remove
SortStress from the list of workloads where threaded minivm is faster, and state
that its 1.06 ratio makes it slightly slower according to the ratio definition
on line 215.
- Around line 290-292: Update the threaded-table scope explanation immediately
following the benchmark table to describe the currently listed zero-allocation
array and struct cases, removing references to allocation-bearing array, struct,
and map cases. Keep the explanation aligned with the benchmark rows shown in
docs/benchmarks.md.
---
Nitpick comments:
In `@interp/interp.go`:
- Line 63: Replace the interpreter’s local GC marking worklist with a reusable
markWork field. In the marking traversal around push at line 2337, reset
markWork to length zero before each traversal, use it for queued addresses, and
retain its backing capacity for subsequent traversals; add the field alongside
the existing work storage.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: a3ede9bb-e5a7-4510-8bf1-92f40487f79c
📒 Files selected for processing (2)
docs/benchmarks.mdinterp/interp.go
Summary
types.Structvalues through an interpreter-owned poolreleaseWorktypes.Struct.ResetResults
StructTreeWalkandBinaryTreesnow run with0 B/opand0 allocs/opBinaryTreesimproved from ~1.35x CPython to ~1.22x CPython on the compare benchmark setAllocationGraphandPermutationFlipsremain stable or improved after the refactorValidation
go test ./...go test -tags=compare -run '^$' -bench='^(BenchmarkMemory_(StructTreeWalk|BinaryTrees)|BenchmarkControl_(IterativeFib|Sieve)|BenchmarkMemory_(AllocationGraph|PermutationFlips))$' -benchmem -benchtime=300ms -count=3 ./benchmarksSummary by CodeRabbit
Performance
Bug Fixes
Documentation
Tests