core/vm: reuse Memory instances #30137 #33056#1974
core/vm: reuse Memory instances #30137 #33056#1974AnilChinchawale merged 1 commit intoXinFinOrg:dev-upgradefrom
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the
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.
Pull request overview
This pull request implements memory pooling for EVM Memory instances to improve performance by reducing allocations. The changes introduce a sync.Pool to reuse Memory objects, add a Free() method to return memory to the pool, and critically fix opReturn/opRevert operations to copy data instead of returning pointers to prevent use-after-free bugs.
Changes:
- Introduced sync.Pool for Memory instances with smart pooling (only buffers ≤16KB)
- Changed GetCopy/GetPtr signatures from int64 to uint64 for better type semantics
- Fixed opReturn and opRevert to use GetCopy instead of GetPtr to prevent use-after-free when memory is freed
- Added benchmark test for RETURN operation with various memory sizes
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| core/vm/memory.go | Implements memory pooling with sync.Pool, adds Free() method, changes signatures to uint64, removes bounds checks (safe due to guaranteed resize) |
| core/vm/interpreter.go | Adds mem.Free() call in defer to return memory to pool after execution |
| core/vm/instructions.go | Updates all call sites for new uint64 signatures, critically changes opReturn/opRevert to use GetCopy to prevent use-after-free |
| core/vm/runtime/runtime_test.go | Adds BenchmarkEVM_RETURN to measure performance impact of memory pooling with various return sizes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Proposed changes
Ref:
Types of changes
What types of changes does your code introduce to XDC network?
Put an
✅in the boxes that applyImpacted Components
Which part of the codebase this PR will touch base on,
Put an
✅in the boxes that applyChecklist
Put an
✅in the boxes once you have confirmed below actions (or provide reasons on not doing so) that