-
Notifications
You must be signed in to change notification settings - Fork 119
Description
AIP Discussion
When executing an entry function or a script payload, all their transitive Move module dependencies and friends are traversed first. During the traversal, the gas is charged for every module in the transitive closure, and the closure's size is checked to be within limits. After the traversal, all modules in the closure are verified, and the payload is finally executed. Similarly, when publishing a Move package, the transitive closure of the package's dependencies and friends is traversed first to meter gas and enforce that the closure's size is bounded. We call this approach to meter, load and publish Move modules Eager Loading.
Eager Loading turns out to be overly restrictive for real use cases, and DeFi in particular. For example, DEX aggregators facilitate token swaps across multiple decentralized exchanges using a single contract. They usually include many DEXes as dependencies and struggle with Eager Loading:
- An aggregator may not be able to add a DEX as a dependency due to limits on the size of the transitive closure.
- If one of the dependency DEXes upgrades to use more dependencies, the aggregator contract may become unusable (any call to its functions will hit the limit after the dependency upgrade).
As a result, Eager Loading makes writing Move contracts with many dependencies very challenging, if not impossible.
There are also other problems due to Eager Loading. Even if a transaction is only using a few modules at runtime, all its transitive dependencies will be traversed for gas metering purposes. This increases the gas costs for transactions, and also hurts performance (transaction accesses dependencies not used for execution).
This AIP proposes Lazy Loading - a different approach to metering, loading and publishing of Move modules. When calling an entry function or a script, modules are metered and loaded only when they are used. When publishing a Move package, only modules in a package and their immediate dependencies and friends are metered and loaded.
Read more about it here: https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-127.md