13.5 How Other Runtimes Do It
Few language runtimes run several isolated interpreters in one process. Four that do got there by different routes. CPython retrofitted isolation onto a runtime full of C globals, Ruby added Ractors to an existing VM, and Lua and V8 were built around isolated states from the start. Each is held to the same four questions below.
13.5.1 The evaluation frame
For each runtime, ask:
- What is shared? Heap? Symbol table? GC state? Builtins?
- What is isolated? Per-interpreter namespace? Objects? Allocators?
- How are native extensions handled? Can they load in both? Are they thread-safe?
- What did it cost? Performance, adoption, complexity?
13.5.2 CPython subinterpreters
CPython has had subinterpreters in its C API (Py_NewInterpreter) since version 1.5 in 1997. Until Python 3.12 they all shared one GIL, so they gave isolation without parallelism. PEP 684 (Python 3.12) let a subinterpreter have its own GIL, and PEP 734 (Python 3.14) exposed subinterpreters to Python code as the concurrent.interpreters module. PEP 734 supersedes the older PEP 554 proposal. Each PyInterpreterState holds its own modules and its own garbage collector state; each OS thread running in it has a PyThreadState with its own frame stack.
Isolated state
Modules. Each interpreter has its own sys.modules, sys.path, builtins and __main__, so the same import in two interpreters produces two module objects.
Garbage collection. The cyclic collector’s state has lived in PyInterpreterState since Python 3.9, so each interpreter collects its own objects.
Objects and their reference counts. Ordinary objects are never shared, so a count is only touched under the GIL of the interpreter that owns the object. An object sent to another interpreter is pickled and rebuilt there. memoryview and concurrent.interpreters.Queue are the exceptions that share data.
Native extension handling
Extensions are where the retrofit is hardest, because a lot of C extension code keeps state in C globals. CPython does not try to make that code safe. It refuses it. PEP 684 counts an extension as compatible only if it uses multi-phase initialization, and an interpreter created with check_multi_interp_extensions set raises ImportError for any other extension. The main interpreter still imports everything. An extension author opts in by moving module state into per-module storage and declaring support with the Py_mod_multiple_interpreters slot.
PEP 684 is final in Python 3.12 and PEP 734 is final in Python 3.14, which ships concurrent.interpreters and concurrent.futures.InterpreterPoolExecutor. The module’s own documentation warns that “not all PyPI packages support use in multiple interpreters yet.”
Cost
The cost lands in two places. Extension authors must move module state out of C globals before their code loads in an isolated interpreter. Data that crosses an interpreter boundary is pickled and rebuilt, so a large object costs a full copy.
CPython is pursuing the opposite design at the same time. PEP 703’s free-threaded build removes the GIL from one interpreter instead, and PEP 779 made that build officially supported in Python 3.14. It is not the default build.
13.5.3 Ruby Ractors
Ruby 3.0 introduced Ractors in 2020 as an experimental feature, and Ruby 4.0 still marks them experimental. A Ractor holds one or more threads. Threads inside one Ractor share that Ractor’s lock (the GVL), and threads in different Ractors run in parallel.
Isolated state
Unshareable objects. Most objects are unshareable and usable only by the Ractor that created them. Sending one to another Ractor deep-copies it, or moves it, after which the sender can no longer touch it.
Threads and their frames. Each Ractor has its own threads, and so its own call frames and locals.
Native extension handling
Ruby treats every C extension as Ractor-unsafe by default. Methods from an unsafe extension may be called only from the main Ractor; calling one from any other Ractor raises Ractor::UnsafeError. An extension that has been checked calls rb_ext_ractor_safe(true) in its Init_ function, which marks all of its methods safe.
Cost
The language checks the sharing rules at run time. That is safer than relying on convention, and it is also restrictive: a program cannot share mutable state between Ractors at all. Through Ruby 4.0 every Ractor stopped for every collection, and Ruby’s own proposal for per-Ractor GC (Feature #22227) names that pause as a cost that grows with the number of Ractors. The 4.1.0-preview1 collector is the answer to it.
13.5.4 Lua states
The Lua C library has no global variables. The 5.4 reference manual says so directly: the library “is fully reentrant” and keeps everything it needs “in a dynamic structure, called the Lua state”. lua_newstate “creates a new independent state”.
Isolated state
Everything the Lua library owns. A state is not safe to use from two OS threads at once: by default lua_lock and lua_unlock are empty macros, so the embedder must keep each state on one thread at a time. A Lua “thread” is a coroutine inside one state, not an OS thread.
Native modules
Lua is mostly embedded, and the C code around it usually belongs to the host application, which passes a state explicitly to every call. C modules can also be loaded with require. Every API function takes the state as its first argument, so a module sees only the state it was handed. Its own C statics are a different matter: a module loaded into two states is mapped once, and its statics are shared, as they would be in R.
lua_State *L1 = luaL_newstate();
lua_State *L2 = luaL_newstate();
my_c_function(L1); // C code sees L1
my_c_function(L2); // C code sees L2, different stateThe embedder controls initialization, and nothing in the Lua library registers anything process-wide.
Cost
Lua never had to retrofit isolation, so it paid nothing for it. The price shows up elsewhere: a state gives no parallelism by itself, so an embedder that wants parallel work runs one state per OS thread and copies data between them.
13.5.5 V8 isolates
V8, the JavaScript engine in Chrome and Node.js, calls its unit an isolate. The embedder’s guide defines it as “a VM instance with its own heap”, and the API header is blunt: “V8 isolates have completely separate states. Objects from one isolate must not be used in other isolates.”
Isolated state
Heap. Each isolate owns its heap. The garbage collector runs per isolate.
Execution state. Each isolate has its own stack and exception state. “An isolate can be entered by at most one thread at any given time”, and v8::Locker hands it from one thread to another.
Native objects
C++ code using the V8 API creates isolates explicitly and passes them to every call.
v8::Isolate::CreateParams params;
params.array_buffer_allocator =
v8::ArrayBuffer::Allocator::NewDefaultAllocator();
v8::Isolate* iso1 = v8::Isolate::New(params);
v8::Isolate* iso2 = v8::Isolate::New(params);
MyFunction(iso1); // sees iso1
MyFunction(iso2); // sees iso2, a separate heapIsolation is explicit in the API. V8 still has process-wide setup: the platform and v8::V8::Initialize() run once per process, before any isolate exists.
Cost
Each isolate carries its own heap, so a process with many isolates pays for many heaps, and no collector can reclaim one isolate’s garbage on behalf of another. Data crosses between isolates by structured clone, which is a copy, unless it is a transferred ArrayBuffer or a SharedArrayBuffer. Node.js worker threads each get their own heap with its own size limits (resourceLimits), and Cloudflare’s Workers runtime runs “hundreds or thousands of isolates” in one runtime instance.
13.5.6 Comparison table
| Question | CPython (own GIL) | Ruby | Lua | V8 |
|---|---|---|---|---|
| Shared object heap? | No, own allocator state | Yes through 4.0 | No | No |
| Shared GC state? | No, per interpreter since 3.9 | Yes through 4.0, per Ractor in 4.1 preview | No | No |
| Shared builtins? | Immortal objects (PEP 683) | Shareable objects only | No | Builtin code only |
| Native code that is not marked safe | Import refused | Callable from the main Ractor only | Up to the module | Up to the embedder |
| How data crosses | Pickled copy, buffers shared | Deep copy or move | Through C, by the embedder | Structured clone, SharedArrayBuffer |
| Status | Final, 3.12 (C API) and 3.14 (Python) | Experimental | Core design | Core design |
13.5.7 Lessons for R
Lua and V8 show that per-interpreter heaps remove GC coupling. No collector in either touches another state’s objects. threaded-r now builds each interpreter with its own heap and collector, and its churn gate, which counts nodes on a new interpreter’s generation rings that live in the main heap, reads zero.
Ruby shows what language-level enforcement buys. A deeply frozen object is a boundary the runtime checks. R has nothing like Ractor.make_shareable, so copying is the only guarantee threaded-r can give today.
CPython and Ruby show how to retrofit without breaking old extensions. Both refuse native code that has not opted in, and both let the main interpreter keep loading everything.
All four isolate by default and share by exception. The opposite design, one heap shared by every thread with synchronization on objects, is what the JVM does and what CPython’s free-threaded build does inside one interpreter. The JVM needs every native library to be thread-safe, which is the assumption R’s compiled packages cannot meet. Free-threaded CPython avoids that demand only by turning the GIL back on, with a warning, when it imports an extension that has not declared support for free threading.
13.5.8 Lessons for threaded-r
threaded-r sits closest to CPython: a retrofit of an old C runtime, isolation by default, and data crossing between interpreters by serialization over channels. Its rule for compiled code is the CPython and Ruby rule too. A shared object is confined to the interpreter that loaded it first, unless the package declares itself capable of running in more than one. What threaded-r lacks is Ruby’s run-time check on shared values, because R has no notion of a deeply frozen object.
Further reading
- PEP 684, “A Per-Interpreter GIL” <https://peps.python.org/pep-0684/>, Eric Snow. Final, Python 3.12.
- PEP 734, “Multiple Interpreters in the Stdlib” <https://peps.python.org/pep-0734/>, Eric Snow. Final, Python 3.14; supersedes PEP 554.
concurrent.interpreters<https://docs.python.org/3/library/concurrent.interpreters.html>, the Python 3.14 module documentation.- Multiple interpreters in a Python process <https://docs.python.org/3/c-api/subinterpreters.html>, CPython C API documentation, including how single-phase and multi-phase extensions behave.
- Ractor, Ruby’s Actor-like concurrency abstraction <https://docs.ruby-lang.org/en/master/language/ractor_md.html>, Ruby documentation.
- Ruby 4.1.0-preview1 release notes <https://www.ruby-lang.org/en/news/2026/10/12/ruby-4-1-0-preview1-released/>, for per-Ractor GC.
- Lua 5.4 Reference Manual, section 4, “The Application Program Interface” <https://www.lua.org/manual/5.4/manual.html#4>.
v8::Isolateclass reference <https://v8.github.io/api/head/classv8_1_1Isolate.html>, V8 API documentation.- Erlang Efficiency Guide, “Processes” <https://www.erlang.org/doc/system/eff_guide_processes.html>, on per-process heaps and what a message send copies.
Where this appears
- threaded-r Retrofit challenge: how to add isolation without rewriting thousands of packages.
- r-in-rust (rrs) Clean slate: each interpreter owns its state from the start, the way a Lua state or a V8 isolate does.