go-ethereum icon indicating copy to clipboard operation
go-ethereum copied to clipboard

core, trie: cache the code chunking in contract

Open gballet opened this issue 3 years ago • 2 comments

Since ChunkifyCode and touchEachChunksOnReadAndChargeGas are dominating the execution time, this PR attempts to cache the values as much as possible, in order to reduce the amount of time these functions are called.

gballet avatar Aug 11 '22 11:08 gballet

Before: ChunkifyCode dominates execution time

profile003

Current state: execution sped up by; a factor 2, and touchEachChunksOnReadAndChargeGas now dominates profile004

Both functions were called too often, because chunking is performed in PUSHn instructions, which are among the most common instructions found in a standard EVM bytecode.

gballet avatar Aug 11 '22 11:08 gballet

profile006

Confirmed improvement

gballet avatar Aug 12 '22 09:08 gballet

This is still useful when calling CODECOPY, but contract execution is no longer a problem and EXTCODECOPY won't work. I think a better approach is to create a global code cache. I'm creating an issue for that.

gballet avatar Aug 29 '24 12:08 gballet