Safe lazy-pages implementation #3920
grishasobol
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
As it is discussed in #3917 - current
gear-lazy-pages
impl is not safe, because we handle them inside signal handler. The possible solution is to implement lazy pages using load/store wrapping. To explain the solution let's dived it to several steps.Raw solution
Append system syscalls, which is uploaded page data from storage
On code instrumentation we will change all load/store operations to corresponding wrapper function:
So, as you can see we call imported function for each load/store operation, which cause significant perf decrease. In my measurements the cost of
i32.load
operation becomex60
times bigger. The cost of one FungibleToken transfer becomesx2
times biggergear/examples/fungible-token/tests/benchmarks.rs
Line 208 in a1f9f64
To solve this perf decrease we can append some optimisations in next steps.
Stack optimisation
Taking solution above we just add check that accessed memory interval lies inside stack memory
Because in common programs the most often are stack memory operations, this optimisation can significantly increase performance in comparison with raw solution.
Cash optimisation
Also some already pre processed pages can be stored on some cash on globals. Most programs does not access many pages during execution, so this cache can be not big. For example 16 pages. Having 16 system i32 globals, we can store there already accessed pages and check this global during execution in order to skip syscall calling to already processed pages. The solution with cache is much more difficult and bigger, so I skip more precise implementation here.
Beta Was this translation helpful? Give feedback.
All reactions