13 Multi-Interpreter Architecture
GNU R runs one interpreter per process. My threaded-r project puts several interpreters inside one process and binds each to its own thread. This section explains what state an interpreter must own, what can be shared, and what my prior work learned about this bet.
This is the central architectural bet of my work. It removes the per-process cost of a worker: there is no new process to start and no second copy of the runtime’s code in memory. It does not remove copying, because values still cross between interpreters by serialization. And it creates a new problem: deciding which global state must stay global and which can be split per interpreter.
After this section
- Describe the difference between process-global state and per-interpreter state
- Explain why some state must stay global and why some can be isolated
- Compare my multi-interpreter strategy to other runtimes that tried it
- Identify the shared memory hazards that this architecture creates
The pages
Multi-Interpreter Architecture. The design of multiple isolated interpreters inside one process and the hazards it solves and creates.
What State Belongs to an Interpreter. An inventory of runtime state and where each piece lives in the three-level model.
Interpreter Lifecycle and Thread Affinity. Creation, initialization, execution, interruption, and teardown. Why one thread owns each interpreter.
Packages and Namespaces Across Interpreters. The hardest unsolved part. Native packages assume process-global state. Also covers how five earlier R implementations handled compiled code.
How Other Runtimes Do It. CPython subinterpreters, Ruby Ractors, Lua states, and V8 isolates. What each chose and what it cost them.
Before this section
Read R Runtime Internals, Concurrency and Parallelism, and IPC and Data Movement.
Where this leads
This is my work. threaded-r uses this architecture. Every architectural choice in my design decisions and experiments depends on it.
ABI, FFI, and Compatibility explains the constraint that makes this architecture necessary.
Shared Immutable Vectors and Arenas, Pools, and Immortal Data cover how to share data without copying and how to allocate shared constants efficiently. sunlight and Fork, Copy-on-Write, and the First GC explore prewarmed process pools and template processes. Serialization and Large-Object Transfer and Chunking cover data movement protocols between interpreters.