13.5 How Other Runtimes Do It

MULTI-INTERPRETERSTATUS: DEVELOPINGLEVEL: DEEPREVIEWED: 2026-11-15

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:

  1. What is shared? Heap? Symbol table? GC state? Builtins?
  2. What is isolated? Per-interpreter namespace? Objects? Allocators?
  3. How are native extensions handled? Can they load in both? Are they thread-safe?
  4. 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.

Shared state

The process. File descriptors, the C library’s malloc, and every C static of every extension module. Python objects themselves do not come from a shared pool: an interpreter with its own GIL must also have its own object allocator state (use_main_obmalloc = 0 in PyInterpreterConfig).

Immortal builtin objects. None, True, False, the small integers and the static types are shared by pointer. PEP 683 (Python 3.12) made them immortal by fixing their reference count at a reserved value, so interpreters running under different GILs can use them without the count ever deciding when they are freed.

Extension code and its C globals. A shared library is mapped once per process. With multi-phase initialization (PEP 489) each interpreter gets its own module object, but the C API documentation is explicit that “only C-level static and global variables are shared between these module objects.”

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.

Shared state

The heap, through Ruby 4.0. All Ractors allocate from one VM-wide heap, and every garbage collection stops all of them. Ruby 4.1.0-preview1 (October 2026) changes the default collector to collect each Ractor’s heap on its own thread, with a stop-the-world collection only when something global has to be reclaimed.

Classes and modules. Class and module objects are always shareable, which is how every Ractor can call the same methods.

Deeply frozen objects. An object is shareable when it is frozen and everything it refers to is shareable too. [1, [2], 3].freeze is not shareable, because the inner array is not frozen. Ractor.make_shareable freezes the whole graph. Integers, floats, symbols, true, false and nil are always shareable.

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”.

Shared state

Nothing inside Lua. Each state has its own heap and collector, its own string table, its own registry and globals, and the allocator function it was given at lua_newstate. A value in one state cannot refer to a value in another; the embedder moves data between states through C. What states do share is the process, including every C global in the host program and in any C module loaded into more than one 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 state

The 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.”

Shared state

The compiled builtins. Since 2018 (Chrome 69 on x64), V8’s built-in functions are embedded in the binary, so the process keeps one copy of that code and every isolate runs it.

The bytes behind a SharedArrayBuffer. The JavaScript objects stay per-isolate, but the memory a SharedArrayBuffer points at can be reached from more than one isolate. Node.js worker threads and Web Workers share memory this way.

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 heap

Isolation 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

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.

Where to go next

Back to top