You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’ve compiled from_rust_9998.wat to zkASM and executed it in the same framework as existing benchmarks. Although the Rust code has fewer loop iterations (9_998 vs 10_000), the resulting from_rust_9998.zkasm requires more cycles: 100_004 cycles.
That’s almost twice as many as from_rust.zkasm, but still less than handwritten WAT.
Per loop iteration an extra element of the sequence is added.
That’s probably why it requires less cycles than handwritten.wat which adds only one element per loop.
It is counting down instead of up.
Possible cause
Just some initial thoughts: In meetings it was mentioned that from_rust.wat is efficient due to loop unrolling. With a number of iterations less favorable to loop unrolling the generated WASM might become less efficient.
Num loop iterations known at compile time?
Often the number of loop iterations is not known at compile time. We may want to figure out how that affects the generated WASM and zkASM.
Low number of loop iterations
For instance for 0..100 the compiler seems to propagate and fold constants as there is no loop at all in the resulting WAT:
Modifying the Rust code for Fibonacci by @Akashin to loop over
0..9998
instead of0..10000
yields quite different WASM:Note that
(start $main)
was added manually.Number of cycles
I’ve compiled
from_rust_9998.wat
to zkASM and executed it in the same framework as existing benchmarks. Although the Rust code has fewer loop iterations (9_998 vs 10_000), the resultingfrom_rust_9998.zkasm
requires more cycles: 100_004 cycles.That’s almost twice as many as
from_rust.zkasm
, but still less than handwritten WAT.wasmtime/cranelift/zkasm_data/benchmarks/fibonacci/state.csv
Lines 1 to 4 in e7eb24d
What happens in
from_rust_9998.wat
handwritten.wat
which adds only one element per loop.Possible cause
Just some initial thoughts: In meetings it was mentioned that
from_rust.wat
is efficient due to loop unrolling. With a number of iterations less favorable to loop unrolling the generated WASM might become less efficient.Num loop iterations known at compile time?
Often the number of loop iterations is not known at compile time. We may want to figure out how that affects the generated WASM and zkASM.
Low number of loop iterations
For instance for
0..100
the compiler seems to propagate and fold constants as there is no loop at all in the resulting WAT:Potential action items
The text was updated successfully, but these errors were encountered: