perf(core): test a recursive word's base case at the call site
CI / check (push) Has been cancelled

A recursive Forth word almost always opens with a guard that returns early,
so every leaf of the recursion costs a call whose whole body is that test.
`Call(self)` now compiles as `<guard> IF <what the guard returns> ELSE
Call(self) THEN`, which is what the callee would have done on entry anyway.
Half of fib's nodes are leaves: Fibonacci(25) 356 -> 237 us, 1.24x sf64 ->
0.83x, so all five benchmarks now beat it.

The guard runs twice along the recursive path, hence the bounds: at most six
effect-free operations, at most four call sites, never a tail call. WS-018.
This commit is contained in:
Oleksandr Kozachuk
2026-08-09 18:27:25 +02:00
parent 645c2dadd7
commit e963e636d3
8 changed files with 394 additions and 37 deletions
+1 -1
View File
@@ -746,7 +746,7 @@ fn perf_benchmarks() -> Vec<PerfBenchmark> {
verify: "25 FIB",
expected: 75025,
samples: 5,
max_ratio: 0.17,
max_ratio: 0.10,
},
PerfBenchmark {
name: "Factorial(12)x100K",