Skip to content

vm: implement contract pool#3156

Merged
zzzckck merged 1 commit intodevelopfrom
contract-pool
Jun 10, 2025
Merged

vm: implement contract pool#3156
zzzckck merged 1 commit intodevelopfrom
contract-pool

Conversation

@MatusKysel
Copy link
Copy Markdown
Contributor

@MatusKysel MatusKysel commented Jun 9, 2025

Optimize Contract Pool Implementation

Changes

  • Replaced custom contract pool implementation with a global sync.Pool
  • Simplified the API by removing the ContractPool struct and making functions package-level
  • Improved JUMPDEST analysis reuse by properly handling parent contract context
  • Removed unnecessary cleanup and size tracking functions
  • Optimized memory usage by letting sync.Pool handle object lifecycle

Technical Details

  • Changed from instance-based pool to a global sync.Pool for better performance
  • Removed manual mutex locking as sync.Pool is thread-safe by design
  • Improved JUMPDEST analysis reuse by checking parent contract context before creating new map
  • Removed redundant cleanup of contract fields as they are reset on next use
  • Simplified the API to just GetContract and ReturnContract functions

Benefits

  • Better performance through optimized object reuse
  • Reduced memory allocations
  • Automatic cleanup of unused objects by garbage collector
  • Thread-safe by design using sync.Pool
  • More efficient JUMPDEST analysis reuse

Benchmarks

image image

@MatusKysel MatusKysel requested a review from Copilot June 9, 2025 08:28

This comment was marked as outdated.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR replaces the custom ContractPool with a global sync.Pool, introduces GetContract/ReturnContract, and updates all call sites to use the new pool API.

  • Switched to a global sync.Pool and removed NewContract/ContractPool struct.
  • Updated EVM methods and tests to use GetContract and defer ReturnContract.
  • Simplified return of leftover gas in create and removed manual cleanup.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/state_test.go Switched NewContract to GetContract and added defer ReturnContract
eth/tracers/logger/logger_test.go Updated logger tests to use GetContract/ReturnContract
eth/tracers/js/tracer_test.go Replaced NewContract with GetContract and deferred return in JS tracer tests
core/vm/instructions_test.go Updated NewContract to GetContract and added defer ReturnContract
core/vm/evm.go Replaced all NewContract calls with GetContract and deferred ReturnContract
core/vm/contract_pool.go Added new GetContract/ReturnContract implementation with sync.Pool
core/vm/contract.go Removed old NewContract function
Comments suppressed due to low confidence (1)

core/vm/contract_pool.go:44

  • Exported functions should have a GoDoc comment. Add a comment above ReturnContract explaining its behavior, e.g., // ReturnContract returns a Contract to the pool for reuse.
func ReturnContract(contract *Contract) {

@MatusKysel MatusKysel marked this pull request as ready for review June 9, 2025 09:19
@zzzckck zzzckck merged commit 31222e6 into develop Jun 10, 2025
7 checks passed
@zzzckck zzzckck deleted the contract-pool branch June 10, 2025 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants