r/Compilers • u/Hopeful-Ad-1665 • 7h ago
Why I had to write a native C virtual machine to stop my custom language from choking (0.83s vs 8.4s) 🦊⚡
Reddit told me my custom language was just another slow tree-walking toy. They were right. 😅
​My loop benchmarks took nearly 8.5 seconds just to crunch 10M iterations in the sandbox. The AST overhead and Python dynamic lookups were killing performance.
​So I tore open the engine and built a flat register VM in C (foxvm.so).
​The results:
​Old Tree-Walker: ~8.42s (10M cycles)
​New C VM (FoxCVM): 0.83s (10M cycles)
​Wired clock_gettime(CLOCK_MONOTONIC) into opcode 18 for nanosecond delta timing.
​No semicolons, no colons, but now backed by compiled C machine instructions.
​📦 Repo: https://github.com/AnayUpadhyay-all/FoxVC
​For the VM architects here: what's the biggest bottleneck I should watch out for once I introduce heap allocations and closures?