What This Corpus Teaches

STATUS: STABLELEVEL: INTROREVIEWED: 2026-11-18

When I started patching GNU R to run multiple interpreters in one process, I needed to understand what R does at runtime and why threads make that hard. I could not find this material in one place, so I wrote down what I had to learn. This corpus teaches what R does, how concurrent systems work, and how to judge a runtime engineering choice. It expects you to write R and Python confidently and to debug code. It does not assume a background in operating systems, compilers, or concurrent programming.

The three layers

Most topics in this corpus move through the same three layers. Read to the depth you need.

Observable behavior. What you can see and measure from R. Changing one element of a vector that a second name also points to copies the whole vector, and memory jumps. An argument that a function never uses is never evaluated. A new worker process can take seconds to start. All of this can be measured without knowing why it happens.

Underlying mechanism. The runtime work that produces that behavior, and the layer most of the corpus is about. An R object lives at an address on the heap, and two names can point at the same object. Environments bind names to values. The garbage collector walks every object the program can still reach and frees the rest. Threads that share data take turns through locks, and the waiting serializes their work.

Engineering consequence. What those mechanisms mean for anyone who changes the runtime. My three projects meet the same constraints and answer them differently. Several interpreters in one GNU R process must keep their state separate, which R was never designed to do. An interpreter written in Rust can keep global mutable state out of its code, with a gate check that runs before every commit to hold it there. A forkserver gets warm workers quickly, at the price of everything the workers inherit from the template.

The order of the material

The sidebar groups the corpus into six sections, ordered from observation to mechanism to design to implementation. Later sections assume the ideas of earlier ones, but each page names its own prerequisites, so you can start in any section.

Start Here

This group holds this page, Start from a Symptom, the concept map, the orientation pages, the reading paths, the concept index and the glossary. If something went wrong in your own code and you do not know why, start from the symptom page.

R in Practice

Parallel R as a working scientist meets it: whether parallelism will help a given workload, which execution model fits it, what data movement and random number streams do to the result, and how to measure it. The section ends with the seven constraints that make R hard to parallelize. These pages stay close to the observable layer and link down to the mechanisms.

How R Works

Interpreters in general, then memory, then GNU R itself: what an R value is in memory and when R copies it, how the garbage collector finds unreachable objects, and how environments, promises and closures chain together. The section closes on the R C API, the interface between R and compiled code. Thousands of compiled packages call that interface, which limits how far the runtime can change without breaking them.

How Parallel Systems Work

Threads, locks, atomics, scheduling, interprocess communication, the operating system and the CPU, each taught as far as R needs it. A work-stealing scheduler moves tasks to idle cores. Atomic operations let threads coordinate without a lock, and cache lines decide what that coordination costs. The operating system pages cover fork, virtual memory and signals, the process machinery that R’s parallel packages rely on.

Architecture Lab

Designs for parallel R, compared on one tension: isolated workers are safe but each pays its own startup and memory, while shared state is cheap but forces synchronization. The multi-interpreter pages open the section, and the approach pages compare processes, threads and interpreters, shared memory and message passing, reference counting and tracing collection, AST walking and bytecode, and copying and zero-copy transfer. Design questions, experiments, decision records and the project pages follow. My three projects take two positions on that tension: sunlight keeps isolated processes and cuts their startup cost, while threaded-r and r-in-rust keep state isolated inside one process.

Implementation Foundations

Rust for runtime work: ownership, borrowing and lifetimes, Arc and Mutex, the Send and Sync traits, enums for runtime values, and unsafe code at the boundary with R’s C API. Rust is memory safe without a garbage collector of its own, so an R interpreter written in it runs only the collector it implements. Two short pages point to where the runtime pages teach data structures and algorithms.

Connections between pages

Four aids connect the pages. A “Before this page” line above the text names the prerequisites, so you can walk back to foundations when something is unfamiliar. “Where to go next” at the foot carries you forward through a topic.

The concept index lists every concept and the pages that teach it, for when you know the idea and not the section it lives in.

Technical terms link to the glossary at first use. Hovering over a linked term shows its definition without leaving the page.

Out of scope

  • It is not a general operating systems, compiler, or Rust course. A systems topic appears only when it explains an R mechanism or a decision in one of my projects.
  • It does not document any one parallel R package. Package APIs change faster than the mechanisms under them, so packages appear as examples.
  • It is not a project diary. Experiments and decisions appear as evidence for a concept.
  • It does not present untested ideas as facts. Callouts separate verified behavior from hypothesis.

Where the projects fit

My three projects are work-in-progress experiments, each testing one approach to parallel R. threaded-r patches GNU R so that several interpreters run in one process, each owned by one thread. r-in-rust is an R interpreter written from scratch in Rust, with no global mutable state in the interpreter. sunlight is an R package that loads a set of packages once in a template process and forks workers from it, so the workers start warm.

A page that one of these projects depends on ends with a “Where this appears” section that links to it.

Where to go next

Back to top