AI Briefing
KO

How to build a fast dynamic language interpreter

·2026.04.22 12:17

Key point

A case study of pushing an AST interpreter up to 1.9x faster than CPython through 21 stages of optimization.

Details

This article outlines, step by step, how to significantly boost performance for a direct AST-walking interpreter of a dynamic language called Zef, without using JIT or bytecode.

The initial baseline was 35x slower than CPython 3.10, 80x slower than Lua 5.4.7, and 23x slower than QuickJS-ng 0.14.0, but by accumulating multiple optimizations, it achieved a 16.646x speedup. Including the incomplete Yolo-C++ port, it became 66.962x faster than the baseline, recording 1.889x faster than CPython 3.10.

The key improvements are as follows.

  • Separated operators and RMW from string dispatch and switched to direct calls
  • Reduced the IntObject check path to avoid isInt() calls
  • Switched string-based lookups to Symbol pointer-based lookups, cutting hashing and comparison costs
  • Split out valueinlines.h so important functions can be inlined
  • Redesigned Object, ClassObject, and Context structures to switch to Storage/Offset-based access
  • Combined inline cache and watchpoint at the interpreter level to specialize property access and method calls

Experiments were conducted on Ubuntu 22.04.5, Intel Core Ultra 5 135U, 32GB RAM, using the average of 30 random runs. Benchmarks used Richards, DeltaBlue, N-Body, and Splay from ScriptBench1.

The gist of the article is that, even without mature VM technology, an AST interpreter can be made considerably fast if value representation, object model, name resolution, and caching structures are well designed.

This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.

Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.