Hasty Briefsbeta

Bilingual

Faster interpreters in Go: Catching up with C++

a year ago
  • #SQL
  • #Performance
  • #Go
  • Vitess replaced its AST-based SQL evaluation engine with a Virtual Machine (VM) written in Go, achieving performance comparable to MySQL's C++ implementation.
  • The new VM is not only faster but also easier to maintain, despite being orders of magnitude more efficient.
  • Vitess's evaluation engine supports complex SQL expressions that cannot be executed directly in MySQL, ensuring compatibility and accuracy.
  • The VM uses static typing derived from semantic analysis, allowing for specialized bytecode without runtime type checks.
  • A unique callback-based VM design in Go avoids traditional switch-based dispatch, improving performance and simplifying implementation.
  • De-optimization is used for corner cases where static typing fails, falling back to the AST interpreter for dynamic type handling.
  • Benchmarks show the new VM is up to 20x faster than the original AST interpreter and matches MySQL's C++ performance in many cases.
  • The VM design minimizes memory allocations, further enhancing performance.
  • JIT compilation is deemed unnecessary due to the high-level nature of SQL operations and the already low dispatch overhead.