Lean Kernel Arena / perf/shift-cascade

Test "perf/shift-cascade"

Expected: 👍 accept · Size: 256.3 KB · Lines: 5.1 k · lean4export: 3.1.0 · Lean: 4.36.0 · Timeout: 40.0 s · 📄 Declaration · 🔗 Source

Stress test for cascading substitution overhead in kernel let processing.

N nested let bindings inside a lambda, where each value references the outer lambda parameter and the previous binding:

fun (a : Nat → Nat) => let f₁ := fun x => a x let f₂ := fun x => a (f₁ x) ... let fₙ := fun x => a (fₙ₋₁ x) fₙ 0

The kernel processes each let by substituting the value into the body. Each value has a free bvar (references a), so substitution under inner binders creates shifted copies. In a de Bruijn kernel with deferred shifts, these Shift(val, offset) wrappers accumulate: step k must traverse through O(k) wrappers from previous steps, giving O(N²) total work.

A locally-nameless kernel substitutes fvars that need no shifting, giving O(N) total.

N=1000 in the Lean source. Increase to stress further.

Checker Result ⏱️ 🧠
nano-lean 👍 2.11 ms (÷24) 36.3 MB (÷2.6)
gruszka 👍 3.65 ms (÷14) 77.1 MB (-18%)
mathgraph 👍 3.20 ms (÷16) 36.2 MB (÷2.6)
sokonanoda 👍 3.11 ms (÷16) 36.2 MB (÷2.6)
pestka 👍 19.2 ms (÷2.6) 23.0 MB (÷4.1)
kefir 👍 3.86 ms (÷13) 7.1 MB (÷13)
kefir-wasm 👍 205 ms (×4.0) 107.3 MB (+14%)
con-ron 👍 34.1 ms (-33%) 54.2 MB (-43%)
con-ron-stream 👍 34.7 ms (-32%) 49.7 MB (-47%)
con-agua 👍 25.9 ms (-49%) 15.3 MB (÷6.2)
nanobruijn 👍 260 ms (×5.1) 63.3 MB (-33%)
nanoda 👍 6.36 ms (÷8.0) 4.1 MB (÷23)
con-leche 👍 11.4 ms (÷4.5) 31.4 MB (÷3.0)
pestka-wasm 👍 580 ms (×11) 396.5 MB (×4.2)
official-nightly 👍 50.5 ms (0%) 99.3 MB (+5%)
eink0rn 👍 11.2 ms (÷4.5) 26.3 MB (÷3.6)
official 👍 50.8 ms 94.4 MB
ind-models 👍 120 ms (×2.4) 115.0 MB (+22%)
kiota 👍 1.94 s (×38) 664.4 MB (×7.0)
tenet 👍 155 ms (×3.1) 51.2 MB (-46%)
tenet-hs 👍 45.4 ms (-11%) 73.2 MB (-22%)
logos-kernel 👍 3.69 ms (÷14) 6.6 MB (÷14)
evmlean 👍 9.49 s (×187) 300.0 MB (×3.2)
mini 👍 1.86 s (×37) 66.2 MB (-30%)
overfull ⌛ — —
lean4lean 👍 50.0 ms (-2%) 91.6 MB (-3%)
lean4cobol 👍 143 ms (×2.8) 16.9 MB (÷5.6)
tenet-jvm 👍 285 ms (×5.6) 94.4 MB (0%)
nanoclo 👍 4.55 ms (÷11) 50.5 MB (-46%)
vow-lean-kernel 👍 7.58 s (×149) 147.4 MB (+56%)
canonical-min 👍 408 ms (×8.0) 1.0 GB (×11)
lazylean 👍 88.1 ms (+74%) 31.5 MB (÷3.0)
rpylean 👍 2.37 ms (÷21) 12.3 MB (÷7.7)
metalean-slow 🚫 14.0 s 318.5 MB
metalean-fast 👍 4.38 s (×86) 542.6 MB (×5.7)
nanoclo-fortran 👍 13.5 ms (÷3.8) 7.3 MB (÷13)