-
Notifications
You must be signed in to change notification settings - Fork 759
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
statemanager: cache and other refactors #3569
Conversation
This reverts commit d7d1dab.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more. |
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.
Looks great so far! 🤩
The one major thing which I would still do structurally differently is that I think we should pass in the cache options directly to the Caches
class and - for the state managers - take an initialized Caches
object as the option input (and no cache options at all).
The we can remove the default initialization this._caches = new Caches(....)
and go with no-cache-as-default.
Default initializations are major tree shaking killers. If we remove, a huge block of code goes away (if not used), so all caching code + the large LRU and js-sdsl dependencies.
It is a bit more to do for users on the UX side (so if caches should be used one needs to pass over: { caches: new Caches() }
(or with some options, but I would think that this is very much worth it.
Just did that! It did involve some other changes, notably in tests and in the default VM.create() state manager instantiation. I have decided to default to using Caches() (so, same behavior as before) for the default VM as a lot of vm packages tests seem to rely on that. |
Made some more progess with making cache optional and fixing tests where necessary. With regards to your comment: I'm actually having a broader reflection about the handling of the undefined caches. I'm not a fan of the complex I don't have a clear full picture right now. We currently instantiate each cache (account, storage, code) with defaults, unless |
If the caches are optional, can't you just do this.account?.del(key)
this.storage?.del(key)
this.storage?.get(key) |
Pretty much what I have ended up doing, yes! |
Yes, agree |
size: this.config.codeCache, | ||
}, | ||
caches: new Caches({ | ||
accountCacheOpts: { |
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.
I think we can fully drop the CacheOpts
from this key, makes it nicer to digest/read and remains fully expressive.
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.
(same for others of course)
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.
done!
size: number | ||
} | ||
|
||
export interface CacheStateManagerOpts { |
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.
Maybe drop the StateManager
here from the name
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.
If we remove StateManager, we'll have a naming conflict with CacheOpts
declared above. I am not 100% satisfied with the general naming, and there is some overlap between these interfaces/types (which makes me want to unify them somehow), but there does not seem to be sufficient overlap to really unify them. Open to suggestions!
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.
Maybe give this a second thought, but I would kill off the deactivate
part and take the size === 0
as the one and only way to deactivate and then remove the CacheOpts
and only use the CachesStateManagerOpts
(then renamed to CacheOpts
😋) as the one thing for all.
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.
Interesting, just seeing this comment I'll give that a try, would really like to simplify further
_storageCache: StorageCache | ||
_contractCache: Map<string, Uint8Array> | ||
|
||
protected _accountCache: AccountCache |
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.
The caches in RPCStateManager
will still be transfered to the new interface, right?
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.
The contractCache
seems different in the rpcStateManager than in the others (i.e. not the ContractCache
class). It would indeed be nice to refactor in a similar fashion here. @acolytec3, why do we use a custom Map<string, Uint8Array> here rather than the ContractCache
class?
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.
I am pretty sure that just some of the inconsistencies we have in state manager and that was rather to have some simple version in and so you can just fully and 1:1 with the original version replace.
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.
I'm 99% sure that is just because the original implementation from the RPCstatemanager just didn't have caches at all. No compelling reason though and the cache will do the same thing.
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.
Just updated to use the same _caches property and type as the other 2
…om/ethereumjs/ethereumjs-monorepo into statemanager/capabilities-refactor
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. One TODO to be cleaned up separately
🎉 |
This reverts some of the changes from #3554 and rebuilds upon them.