SC Module Caching #3560
Replies: 4 comments 7 replies
-
A question remains about the local execution of arbitrary bytecode. The initial solution was using Singlepass as the compiler to avoid making that kind of calls too heavy since they do not use cache most of the time. But doing so requires another set of gas costs specified for that particular case, the work this would require is not justified at the moment. So we are left with 2 choices here:
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Extension to the CL/SP combination. The LRU keys are in the format [SP/CL tag][hash]. Also when the CL-compiled version is available both in the LRU and the HD, we use the LRU module because it avoids deserializing. In the HD, the keys are just [hash] and only the CL version is stored. Memory caching should be enabled in the HD. |
Beta Was this translation helpful? Give feedback.
-
With non-deterministic and finite size HD cache:Modules in blue would be handled in a threaded compilation manager. This is not required for the incoming implementation. Edit: Final implementation will be very similar to this with the following differences:
|
Beta Was this translation helpful? Give feedback.
-
Context
The SC execution recently moved from a system that compiles every bytecode before running it to a cache oriented system that stores compiled modules.
Here is its current state:
The purpose of this discussion is to expose the new behaviour and clarify the remaining grey areas.
Module Caching Flowchart
Initial proposal:
Second proposal (deterministic and with payments specified, relative changes are in blue)
Specifications
Data structures
LRU cache
: stands for Least Recently Used, stored in RAM and will contain the compiled modules of widely used smart contracts. When an SC is called, it moves up. The LRU has a fixed limit, if an SC falls under it will be relegated.HD cache
: stands for Hard Drive, stored in disk memory and will contain the compiled modules (serialized version) of every smart contract in the ledger. It associates a reference counter to the modules.Approximative gas prices:
Add Bytecode
if bytecode is not stored in theHD cache
: Very highAdd Bytecode
if bytecode is stored in theHD cache
: Very LowDelete Bytecode
: Very LowModify Bytecode
: Similar toAdd Bytecode
Execute Bytecode
: Low (if execution compilation is not taken into account)Compilators
Add Bytecode
compilation: Cranelift (slow compilation but optimised output module)Execute Bytecode
compilation: Ideal would be Singlepass (fast compilation but unoptimised output module) but because of relative gas costs will probably be Cranelift as wellDeterminism
LRU cache
data is not necessarily deterministicHD cache
data must be deterministicBeta Was this translation helpful? Give feedback.
All reactions