Feat/Delete EVM instance in AnteHandler #352
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Closes: #351
Summary
Remove the creation of a Geth EVM instance during the AnteHandler balance check.
Notes
Background
Cosmos EVM currently instantiates a full Geth EVM engine twice per transaction—once for pre‑validation (
CanTransfer
) and once for execution—leading to significant CPU, memory, and GC overhead. By eliminating the unnecessary VM spin‑up in the AnteHandler, we can streamline the pre‑validation path without affecting state integrity.Changes
Before: In
ante/evm/07_can_transfer.go
, callevmKeeper.NewEVM()
on every transaction to create a “first” EVM instance and then invokevm.CanTransfer()
.After: Refactored CanTransfer() to remove the
NewEVM()
call and perform a direct balance lookup viaStateDB.GetBalance()
. Same results, but Compact.(Reference: Geth’s pre-validation path also does not spin up an EVM instance.)
All existing tests pass without modification.
Benchmark
Benchstat
go version go1.24.4
cpu : M1 pro, memory : 16 GB
old benchmark
Date 0724 02:10 AM PST
Branch : [old/delete-evm-instance-ante]
latest benchmark
Date 0724 02:40 AM PST
Branch : [feat/delete-evm-instance-ante]
Average time per operation (ns/op): ↓ 4.54%
Heap allocation bytes (B/op): ↓ 11.76%
Heap allocation calls (allocs/op): ↓ 11.78%
Interpretation:
newEVM()
.Expect shorter and less frequent GC pauses in production, resulting in lower processing latency, although this performance gain isn’t reflected in the current benchmark.
Reproduce this benchmark
Since there was no performance improvement, I mocked tx types bank-msg-send
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
main
branchReviewers Checklist
All items are required.
Please add a note if the item is not applicable
and please add your handle next to the items reviewed
if you only reviewed selected items.
I have...
Unreleased
section inCHANGELOG.md