Improve memory metering for WASM VMs #1970
Replies: 3 comments 4 replies
|
Just to add more context, the best return on investment of such change will actually be towards the oracle providers, then the core lending/defi protocols. If oracles will re build and re deploy the existing contracts with the new linear memory reduced, many protocols (mine included) will be more efficent in reading a bunch of prices for complex positions and in the future ETF style contracts calculating NAV, ETF price. |
|
Another alternative that I think should be considered is to increase the 40 MB But, the proposal to credit memory allocated back after the frame is popped seems preferred, given that the memory should have been released then, unless there's some outsized cost to doing so. |
|
Agree with proposed approach of refunding memory on VM teardown, as it makes most contracts cheaper and matches better with reality. Since this is a strict improvement to the host internal (the only observable being cheaper budget number), I think we can fix it and roll it out as an internal improvement in the next protocol. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Problem
As Stellar's DeFi ecosystem grows, protocols built on top of other protocols are performing lots of cross-contract calls. The way memory is metered for WASM VMs puts an artificial ceiling on how many cross-contract calls fit within the per-transaction 40 MB
mem_byteslimit.By default, contracts compiled with
stellar-clideclare a WASM linear memory with a ~1 MiB initial size. Each VM instantiation accrues that amount (+ more) to themem_bytesmeter and does not credit any back when the VM is torn down. For contracts with lots of sequential cross-contract calls, this causes them to hitmem_byteslimits without using much memory.This has impacted builders a few times recently:
Proposal
We add the ability to credit memory allocated for a WASM VM after it's frame is popped back to
mem_bytes.Alternatives
stellar-clican likely safely reduce the WASM stack size down from 1 MiB for contract builds. However, this doesn't help contracts that are already live, like Blend. This should be explored regardless of the outcome of this discussion.All reactions