Lean Kernel Arena (Preview) / perf/shift-cascade

Test "perf/shift-cascade"

Expected: 👍 accept · Size: 256.4 KB · Lines: 5.1 k · lean4export: 3.2.0 · Lean: 4.38.0-nightly-2026-12-03 · 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 ⏱️ 🧠
gruszka 👍 3.66 ms (÷16) 87.2 MB (-24%)
nano-lean 👍 2.12 ms (÷28) 34.3 MB (÷3.3)
pestka 👍 19.2 ms (÷3.1) 23.2 MB (÷4.9)
con-leche 👍 11.2 ms (÷5.3) 31.1 MB (÷3.7)
con-ron 👍 33.5 ms (-44%) 46.1 MB (÷2.5)
nucleus 🚫 76.9 ms 14.6 MB
official 👍 59.4 ms 114.7 MB