Skip to content
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: avoid cloning precompiles #1486

Merged
merged 7 commits into from
Jun 17, 2024
Merged

Conversation

DaniPopes
Copy link
Collaborator

@DaniPopes DaniPopes commented Jun 4, 2024

Precompiles::new().clone().into() would first clone the static default precompiles, then collect them into a new hashmap again in ContextPrecompiles. This shows up as about ~3% in Evm::transact profiles.

Avoid both cloning and collecting by using a CoW structure internally. This requires us to remove the Deref and DerefMut implementations as the internal type will be different depending on whether we have the default static precompiles, or a custom map. This should be fine as we can still support all necessary operations without exposing the underlying map type.

@DaniPopes DaniPopes changed the title perf: avoid cloning precompiles twice perf: avoid cloning precompiles Jun 4, 2024
@DaniPopes DaniPopes marked this pull request as draft June 4, 2024 10:49
@DaniPopes DaniPopes marked this pull request as ready for review June 4, 2024 11:52
@DaniPopes DaniPopes requested a review from rakita June 4, 2024 11:53
@DaniPopes DaniPopes force-pushed the precompile-clone branch 3 times, most recently from 661b8b9 to 64a27a9 Compare June 4, 2024 12:07
Copy link
Member

@rakita rakita left a comment

Choose a reason for hiding this comment

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

good idea!

Added few nit changes:

  • Return Fatal error to not panic.
  • PrecompileCow::Default renamed to PrecompileCow::StaticRef
  • Return Boxed iter from addresses and additionaly added HashMap for addresses in Precompile.

@rakita rakita merged commit de540b6 into bluealloy:main Jun 17, 2024
25 checks passed
This was referenced Jun 17, 2024
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.

2 participants