High-Performance Recursive DFS: The 4-Part Series

An experimental research series attacking the foundational limits of recursion—discovering novel solutions that allow recursive calls to run significantly more efficiently in both time and space.

Part 1 30 Million Stackless TCO
Part 2 2.1 Billion The 32-Bit Ceiling
Part 3 1.52 Trillion Hyper-Dimensional
Part 4 3+ Trillion 5-DOF Arm @ 50 Hz
Part 4

Recursive DFS IV: Recursion Forever

Pre-Emptive Bare-Metal Recursion on a 5-DOF Robotic Arm

Taking the TCO training wheels off: compile-time defunctionalization ([InterceptsLocation]) lowers even non-tail, backtracking recursion into an inlined register machine, pairing compact ring buffers with bit-packed slabs and NVMe paging. Benchmarked in zero-GC C# Native AOT and Rust, an 8 GB Raspberry Pi 5 beats our 192 GB desktop run—passing 3 trillion frames while driving a 5-DOF robotic arm in real time.

Part 3

Recursive DFS III: Hyper-Dimensional Depth

1.52 Trillion Calls Across 192 GB DDR5

From 2.1 billion to 1.52 TRILLION recursive calls. Stripping away node arrays, 32-bit int limits, and bool arrays down to 1 bit per node in ChunkedBitArray—exhausting 192 GB of DDR5 RAM with zero GC pauses.

Part 2

Recursive DFS: 2 BILLION Stack Frames Deep, BEATING Iterative!

Unlocking Undocumented Tail Call Optimization

Stripping away List<int>, generics, and foreach loops until RyuJIT/Native AOT triggered Tail Call Optimization (jmp)—reaching 2.14 billion recursive calls and beating iterative Stack<T>.

Part 1

Recursive DFS: Unexpected Recursion Depth

30 Million Stack Frames Deep — Questioning What Was Possible

820% faster and 30 million stack frames deep—2x deeper than standard C# and 1,500x deeper than Java/Python by replacing reference types and HashSet<T> with value-type structs and bool[] arrays. Hitting this unexpected recursion depth is what caused us to begin questioning what was possible.

The Philosophy of the Series: Why Graphs, Trees, and DFS?

Why obsess over a basic recursive Depth-First Search? Because trees and graphs are everywhere—even outside of computing, and especially at every single layer of a computer. Whether you are looking at embedded systems, digital circuit design, hardware device hierarchies, thread execution paths, file systems, network routing, the topology of the Internet, or UI layout engines (DOM and render trees), you are looking at graphs and trees.

And in today's modern age of Large Language Models (LLMs), Vision Models, and AI, graph traversal is more foundational than ever: neural network backpropagation (reverse-mode automatic differentiation) is literally built on reverse post-order DFS over a computation graph, while reasoning frameworks like Tree-of-Thoughts (ToT), token search trees, and transformer graph traversals are all predicated on DFS and level-order BFS. It is literally all over the place.

In mainstream software engineering, the reflexive rule of thumb is always: "Convert recursion to iteration to prevent stack overflows." Taking a novel, first-principles approach to attacking this very basic recursive problem allows us to dissect what we think we know and test the limits of what is truly possible. I learned a tremendous amount about hardware registers, compilers, OS kernels, and runtime internals from this one simple problem—and it is genuinely mind-blowing to see how far beyond conventional limits you can go when you question what we think is possible.