-
Notifications
You must be signed in to change notification settings - Fork 804
Common: Cache Parameter Values + activated EIPs for current Hardfork / SM copy() fix #2994
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
Conversation
Codecov Report
Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more. |
fa3f5a1
to
21b70f1
Compare
Ok, as already pointed out in a call with Jochem: so this works and is siginifcant! 🎉 I tested by running the blockchain tests on the VM with
Also the > import { Chain, Common, Hardfork } from '@ethereumjs/common'
undefined
> let c = new Common({ chain: Chain.Mainnet })
undefined
> console.time('Total'); for (let i = 0; i < 100000; i++) { let p = c.param('gasPrices', 'push') }; console.timeEnd('Total');
Total: 6.211ms Lol. I fixed one additional thing since tests failed. If tests are passing would be ready for review. 🙂 |
512d544
to
de29f5e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great overall. What is the significance of changing all the private
elements to protected
?
That's our "standard" for the libraries, so preferring |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some remarks and questions :) LGTM overall!
…or users on sub-classing
…with direct _paramsCache() access
ef1e8e8
to
d914cbf
Compare
@acolytec3 @jochem-brouwer thanks for the reviews, have answered and/or applied changes. Ready for re-review once tests pass! 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
First-round performance tests suggests that
Common
param()
reads take a significant amount of time, see:(a similar issue was already mentioned years ago by Patricio from HardHat in some separate peformance tracking issue, just to mention)
Time used in the 100s of miliseconds is significant, since the iteration set of 100000 is relatively close to real world conditions and an amount realistic to be called in e.g. the EVM during a block execution (since the
param()
method is used for every opcode gas calculation e.g.).Looking at the code confirms that this is likely inefficiently coded, since every
param()
read again iterates through both all hardfork files and additionally through all EIP files.This PR therefore aims to introduce a cache with the parameters at hand for currently active set of both hardforks and EIPs. This cache will be rebuild on a hardfork change or an EIP addition (which both either doesn't happen at all or at least doesn't happen often during a Common object livecycle).