Technical Deep Dive

How RunMat Works

Here's how we built a MATLAB runtime that starts in 5ms and runs many workloads significantly faster than existing implementations like GNU Octave.

Traditional MATLAB interpreters can feel sluggish for compute-intensive workloads. RunMat takes a different approach with a V8-inspired architecture that prioritizes performance without sacrificing compatibility.

Why Octave and MATLAB are Slow

Slow Startup: MATLAB takes 10+ seconds to start because it loads massive runtime environments, initializes complex licensing systems, and builds symbol tables from scratch every time. Even with JIT compilation, the startup overhead dominates short-running scripts.

Runtime Inefficiencies: Traditional interpreters execute code line-by-line, translating every operation at runtime. A simple matrix multiplication gets parsed, analyzed, and dispatched to BLAS libraries — every single time. Loop bodies get re-interpreted on each iteration.

The result? You spend more time waiting for MATLAB to start than actually running your code, especially for quick calculations and iterative development.

The RunMat Approach: Adaptive Compilation

RunMat takes a different approach inspired by modern JavaScript engines like V8. Instead of treating every line of code the same, we use adaptive compilation that optimizes frequently-executed code paths.

Phase 1: Instant Execution

Your code runs immediately through our Ignition interpreter — no compilation wait time. Good for interactive exploration, prototyping, and one-off calculations. While executing, we track which functions are called frequently.

Phase 2: Machine Code

Functions that run frequently get upgraded to native machine code via our Turbine JIT compiler. Same code, but now with optimizations like loop unrolling, function inlining, vectorization, and specialized paths for your specific data types and usage patterns.

Why This Approach Wins

Unlike traditional ahead-of-time compilers that optimize for average cases, our JIT compiler sees exactly how your code behaves at runtime. It knows your matrix sizes, your data types, your calling patterns — and optimizes accordingly. The 20% of your code that runs 80% of the time gets the full performance treatment.

Performance Characteristics

Startup Performance
GNU Octave914ms avg
RunMat5ms avg
Speedup182.93× faster
Matrix Operations
GNU Octave822ms avg
RunMat5ms avg
Speedup164.40× faster
Mathematical Functions
GNU Octave868ms avg
RunMat (Interpreter)5.7ms avg
RunMat (JIT)5.3ms avg
Speedup153-163x faster
Control Flow
GNU Octave876ms avg
RunMat5.7ms avg
Speedup154.54x faster
Benchmarks run on Apple M2 Max (32GB RAM) under identical conditions. Full suite available in /benchmarks; reproduce with ./benchmarks/run_benchmarks.sh.

Deep Dive: How the Magic Happens

The Ignition Interpreter: Speed from Day One

When you type A = [1, 2; 3, 4] and press enter, here's what happens in microseconds:

  1. 1. Lexical Analysis: Your MATLAB code gets tokenized into meaningful chunks
  2. 2. Parsing: Tokens become an Abstract Syntax Tree (AST) representing the structure
  3. 3. HIR Translation: The AST becomes High-level Intermediate Representation for optimization
  4. 4. Bytecode Generation: HIR compiles to compact bytecode instructions
  5. 5. Immediate Execution: Bytecode runs instantly while profiling counters track "hot" functions

This entire pipeline completes in under 5ms — faster than most editors can update their syntax highlighting.

The Turbine JIT: When Performance Really Matters

Once a function gets called enough times (our threshold is carefully tuned), Turbine kicks in:

  • • Type Specialization: Generate optimized code paths for your specific data types
  • • Loop Optimization: Unroll tight loops and vectorize operations using SIMD instructions
  • • Function Inlining: Eliminate call overhead for frequently-used builtins like sin() or cos()
  • • Memory Layout Optimization: Arrange data structures for cache-friendly access patterns
  • • Dead Code Elimination: Remove branches that never execute in your specific use case

The result? Machine code optimized for your specific usage patterns, with specialized paths for your data types and calling conventions.

Memory: The Foundation of Speed

MATLAB's strength has always been matrices, so we designed our memory system from the ground up for numerical computing:

Zero-Copy Arrays

Arrays use column-major layout (just like MATLAB) and pass directly to BLAS/LAPACK libraries without any data copying. Large matrix operations can work directly with the underlying memory without unnecessary data movement.

Copy-on-Write Semantics

When you write B = A, we don't copy the entire matrix. Instead, B shares A's memory until you modify one of them. This preserves MATLAB semantics while dramatically reducing memory usage.

Garbage Collection: Smart Memory Management

Scientific computing creates lots of temporary arrays — intermediate results in calculations, temporary matrices in algorithms, etc. Our garbage collector is designed with this pattern in mind:

Generational Collection

Young objects (like temporary calculation results) get collected quickly and frequently. Old objects (like your main data matrices) get touched rarely, minimizing overhead.

Background Threads

Memory cleanup happens in the background while your calculations continue. No more "GC pause" interruptions in the middle of your analysis.

Instant Startup: 2000x Faster Boot Times

Remember how MATLAB takes 10+ seconds to start? It's a symptom of a larger problem. RunMat solves runtime startup time using modern techniques like snapshotting, lightweight runtime design, and fast compilation.

Lightweight Runtime Architecture

Built from the ground up in Rust with minimal startup overhead. No massive Java runtimes, no complex licensing checks, no bloated legacy code. Just a lean, fast runtime that gets out of your way and lets you focus on your work.

Instant Compilation Pipeline

Our compilation pipeline is designed for speed: fast lexing, efficient parsing, and immediate bytecode execution. Combined with pre-warmed snapshots of the standard library, we eliminate the cold-start penalty that plagues traditional environments.

Modern Plotting: Built for the GPU Era

Traditional MATLAB plotting is CPU-bound and struggles with large datasets. We build a clean, GPU-accelerated plotting system that's fast, beautiful and seamlessly integrates with the rest of the runtime:

GPU-Accelerated Rendering

Built on WebGPU (wgpu) with custom WGSL shaders. Designed to handle large datasets efficiently by leveraging GPU acceleration for rendering, with smooth interaction for scatter plots, line charts, and other visualizations.

Interactive by Default

Zoom, pan, rotate — all built-in and responsive. Level-of-detail rendering means performance stays smooth even when you're exploring huge datasets. Because the best insights often come from interactive exploration.

A Complete Scientific Computing Ecosystem

RunMat isn't just a faster interpreter — it's a complete rethinking of the scientific computing experience:

Lightning-Fast REPL

No more waiting for calculations to complete. The interactive shell starts instantly, remembers your variables and functions within your session, and provides fast syntax error detection with clear, helpful error messages.

runmat> A = randn(1000, 1000); B = A * A';
ans = 1000.0

First-Class Jupyter Integration

Built for the notebook era. Install RunMat as a Jupyter kernel with one command, and enjoy the same performance in your favorite notebook environment. Rich display support for plots, matrices, and data structures.

$ runmat --install-kernel
✓ RunMat Jupyter kernel installed successfully!

Modern Cloud & Container Deployment

Single static binary with zero dependencies makes deployment trivial. Run MATLAB code in Docker containers, Kubernetes clusters, or cloud functions. No complex runtime environments, no licensing servers — just copy the binary and go.

$ echo "A = [1, 2; 3, 4]; det(A)" | runmat
ans = -2.0

What's Next: The Future is Bright

We're just getting started. Here's what's coming to make scientific computing even better:

Cross-Platform Deployment: Run Anywhere

Compile your MATLAB code to run on any platform — from embedded microcontrollers and edge devices to web browsers via WebAssembly, mobile devices, and cloud infrastructure. Write once in MATLAB, deploy everywhere from IoT sensors to high-performance clusters.

GPU Compute: Massively Parallel Everything

Why limit matrix operations to your CPU? Direct CUDA and ROCm integration will automatically offload heavy computations to your GPU, turning your graphics card into a scientific supercomputer - without having to purchase yet another license.

Enterprise Freedom: Break the License Prison

No more per-seat licensing, no network license servers, no vendor audits. Deploy RunMat across unlimited machines, scale teams without budget explosions, and never face astronomical renewal costs again. True computational freedom for organizations of any size.

Ready to Dive Deeper?

Explore RunMat's source code or try it yourself to see this architecture in action.