-
Notifications
You must be signed in to change notification settings - Fork 43
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
Recycle VM components in between host calls #827
Comments
I did a quick exploration on possibly sharing VM components between contracts to improve performance. There doesn't seems to be any low-hanging fruits there. Even |
Also, for the same reason caching parsed Wasmi module won't work either, because the |
Caching is probably doable in the context of a single transaction, but crossing transaction boundary is probably fairly challenging: If we were to do it at the transaction level only, I am not sure the benefits would be there. |
We got some feedback today that some contracts want to call other contracts repeatedly (eg. to inquire about the balance of multiple accounts) and so in this context a "first cross contract call to X is charged instantiation, subsequent calls are charged only a cheaper no-module-parsing / cached-instantiation" model makes sense (it's not sensitive to transaction order or anything). |
Fwiw I think we should do this before final, but perhaps a little after we have instrumentation sufficient to quantify the win, so sometime over the summer. It'll be an XDR change (to add a new cost type for cached instantiations) but otherwise the only user visible effect should be things get cheaper. |
(I've just set this to preview 10 and assigned to @jayz22 but that is just for the XDR change -- we can do the rest later) |
FYI, the XDR change for a new ContractCostType::VmCachedInstantiation has been done. The remaining work in env is non-protocol breaking, so can be done after v20 stable release package is out. |
As per discussion today, we will be adding the necessary data structure for storing contract IDs and control flow for charging |
Bumping prio to P0 for adding in the charging control flow. Once done will reduce it back for the actual caching implementation. |
What is our latest thinking on what to cache? Trying to determine the low hanging fruits while maximizing benefit to the user. Got ecosystem feedback today:
|
It would be big improvement to cache contracts at least within single operation as first step. There are use-cases when we need to invoke reasonably limited amount of sub-contracts deployed using single wasm code. |
concerning the deadlock above, I think the most likely-to-work (and not be horribly ugly) solution to this is to pre-parse all modules in the footprint of a given transaction, before we begin executing any. on the one hand it means there's a possibility of "charging someone for work they don't ultimately use" (eg. if they mention a module in their footprint but then, due to some conditional logic in the contract, ultimately never call that module); on the other hand it's a simple model to reason about, and I expect the great majority of cases will benefit from the caching and not be punished by the eager parse (i.e. they will only mention contracts in their footprint that they're actually going to call). |
This is a sketch of the first step in the plan for addressing #1292 and eventually #827 and #1313, namely: - add a bunch of cost types that decompose the current "worst case" VM instantiation cost type - continue to charge the worst case on initial contract upload - _store_ the decomposed cost-type inputs in the ledger, since we can observe them after the initial upload parse - _use_ those decomposed cost-type inputs when doing runtime instantiation - add a module cache - populate the module cache with all modules on host startup - use cached modules during instantiation This PR has accompanying changes in XDR and wasmi: - stellar/stellar-xdr#177 - stellar/rs-stellar-xdr#346 Remaining to do: - [x] determine what the correct set of decomposed cost types even is - [ ] ~add more code to wasmi to enable observing more inputs~ - [x] add cost-type runners / calibrations for all the decomposed cost-types - [x] protocol-gate this new behaviour - [x] make the linker-loop do less work to match the tighter cost model (i.e. complete #1292) - [x] possibly _duplicate_ the set of cost types added here, so we have a cached and uncached version of each, and implement a solution to #827 - [ ] possibly decompose the set sufficiently to model what will happen when we take wasmi 0.32 and enable lazy translation (i.e. complete #1313)
The
VmInstantiation
cost is by far the largest component in the host, due to the underlying cost of parsing the WASM contract and instantiating the VM. This will present bottleneck for contracts that make many cross-contract calls (e.g see #825 (comment)).We could perform optimization such as caching parsed contracts between invocation/tx, or having the host own some shared VM components (e.g.
Engine
, maybe a version ofStore
) for all Vm instantiations to start from.The text was updated successfully, but these errors were encountered: