-
Notifications
You must be signed in to change notification settings - Fork 646
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
contracts: Cache compiled modules #3650
Comments
I think if we enable lazy compilation via Wasmi it should already do a good enough job here even without caching since it would only compile those parts of a contract call that are actually needed for execution. Vanilla caching of Wasmi compiled Wasm modules is not (yet) possible and given that we now have lazy compilation I doubt that it will help much on top of lazy compilation if enabled. I have not implemented Wasmi bytecode (de)serialization so we cannot quickly try it out. Also even with serialized Wasmi bytecode we'd still need structured encoding for it which needs to be parsed (in parts) etc. just like Wasm itself. tldr; I don't think we'd gain much by caching compiled Wasmi bytecode over just using the already available Wasmi lazy option. |
@deuszx You need to update Wasmi in Then enabling the lazy compilation is a one-liner: |
Why not? If we keep the |
Yes if that is a possibility in |
Setting it to blocked for now. We should check if lazy compilation will help enough before adding a fair amount of complexity. |
|
Thanks @pgherveou . While I have you here - @Robbepop and @athei - I've been going through the changes in |
Yes we could use this API technically and it would further improve the startup performance for eager compilation and also to some extend the startup and execution performance in lazy mode since validation in lazy mode is no longer done when lazily compiling a function during its first use. However, the API is |
I understand. I'm not the expert on pallet_contracts of course but it seems like it should be possible to create and maintain the invariant. Thanks for the input. (And the awesome, continuous work on |
The invariant is already established since the @athei What are your thoughts on that? |
I am closing here because after much discussion that this is not really possible without many changes to the wasmi API as we cannot selectively cache modules. We would need to cache all of the modules for a whole call stack. We don't have the runtime memory for that. We will instead rely on lazy compilation to reduce the costs of cross contract calls. |
As of right now we unconditionally load and compile each contract whenever it is called by another contract. This makes the system easy to benchmark and argue about. However, this naive approach slows down use cases where the same code is used multiple times within the same call stack. Implementing a DEX would be such a use case where trading pairs use the same code.
We should implement the following optimization: Store the compiled wasm
Module
of each contract in itsFrame
. Whenever a cross contract happens we search theStack
if there is a contract already using the same code hash. If yes we instantiate a newInstance
from thisModule
. This will skip loading from storage and compilation.We have to check how that interacts with lazy compilation @Robbepop .
We also need to think about how to benchmark this.
The text was updated successfully, but these errors were encountered: