16.2 The Cost of Splitting SYMVALUE

EXPERIMENTSSTATUS: STABLELEVEL: INTERMEDIATEREVIEWED: 2026-11-18

16.2.1 Question

What does it cost to move base-function bindings out of symbol objects into a real hashed base environment? At the time this looked like a prerequisite for per-interpreter base state. In GNU R, base bindings live in the symbol’s SYMVALUE slot, a global fast path: a lookup that reaches base goes straight to the symbol. In a multi-interpreter design, each interpreter needs its own base bindings. Splitting SYMVALUE means moving those bindings to a separate hashed environment per interpreter. What is the performance penalty?

16.2.2 Hypothesis

The design note that preceded the measurement (docs/p4/symbol-value-split.md in threaded-r) predicted that the obvious design would fail. Making the base environment an ordinary hashed environment puts a hash probe on every call to a base function, the hottest path in R, and the project’s gate allows at most a 2 percent single-thread regression (decision D7). A bounded per-interpreter side array, indexed from the symbol, looked like the safer mechanism.

The measurement did not support that prediction.

16.2.3 Setup

R already contains both designs, so nothing needed implementing. When a function is looked up through the global environment, a base symbol flagged BASE_SYM_CACHED is read straight from its SYMVALUE slot, with no hash probe (findFun3 in src/main/envir.c, under FAST_BASE_CACHE_LOOKUP). An identical closure in an attached hashed environment is found through findGlobalVar, which probes R_GlobalCache for the binding. The difference between the two is one hash probe, which is what a base environment without the SYMVALUE fast path would pay.

I ran tools/bench/symvalue-vs-hash.R in the release build. Three cases, all calling a closure with the identical body function(x) x 200,000 times, differing only in where the name is found: the calling frame (the control), the base environment, and an attached hashed environment. Four runs of 90 paired reps, interleaved, not blocked. Effects are Wilcoxon signed-rank pseudomedians over the paired per-rep ratios, with 95 percent intervals, and p is an exact sign test. Run 0 predates the intervals and reports the paired median with a sign count.

16.2.4 Results

run control (base vs local) hashed vs base
1 +0.51%, CI -0.49 to +1.56, p = 1.00 +1.60%, CI +0.60 to +2.77, p = 0.026
2 +0.04%, CI -0.88 to +0.93, p = 0.75 +1.33%, CI +0.39 to +2.19, p = 0.008
3 +0.79%, CI +0.00 to +1.62, p = 0.11 +1.66%, CI +0.76 to +2.54, p = 0.002
0 +0.30%, 48 of 90, p = 0.60 +1.85%, 62 of 90, p = 0.00044

Every lower bound on the treatment is above zero. The control intervals reach down to zero or below, and run 0 reports a sign count only.

An earlier measurement reported 2 to 4 percent. The measurement record (docs/p4/symvalue-measurement.md) lists three defects in the first harness. system.time’s elapsed clock ticks at 1 ms on that machine, and the timings were tens of milliseconds, so the quantization was the same size as the answer being reported. The reps were blocked, all of one case before the next. Blocking cancels jitter but not the drift from a neighboring build running on the same machine. And the accumulator overflowed int32 at i = 65536. The reasoning built on that harness was sound and its conclusion held; the harness underneath it had not been checked.

This measurement is from 2026-08, four runs of 90 paired reps on one machine, WSL2, using release-mode threaded-r. GNU R stores base function bindings in symbol SYMVALUE slots, a global fast path shared by all evaluation.

16.2.5 Interpretation

The point estimates, 1.3 to 1.9 percent, sit under the 2 percent gate on the case built to make hashing look worst, but the upper ends of the intervals reach 2.2 to 2.8 percent. The measurement shows a real, small cost, not one proven to be below the gate. D7 applies the gate to large real programs, where lookup is a smaller share of the time. The cost would buy each interpreter its own base environment with its own bindings.

threaded-r did not adopt this design in the end. Once each interpreter had its own symbol table, ordinary base bindings were already private, in their own symbols’ SYMVALUE slots. So roughly 1,369 base symbols keep the fast path, and only the 38 symbols that interpreters share keep their binding in a per-interpreter record (docs/ledger.md, the “Scope down” decision).

One caution about quoting this figure, which the corpus does on several pages. It does not choose between the two placements later considered for the bindings, a hashed frame on the base environment or a per-interpreter side table, because both pay one hash probe (docs/p4/base-frame-design.md). The number says the hashed design is affordable, and nothing more.

The overhead is the hash probe. Finding the binding through R_GlobalCache takes the symbol’s hash, a probe into the cache’s table, and a read of the binding cell. A direct SYMVALUE read is one memory access. The difference is latency and cache behavior.

only the hashed path pays a probe base environment: no hash probe base-cached flag set read SYMVALUE f(x) probe R_GlobalCache read the binding cell attached hashed environment: one hash probe, then one read

R skips R_GlobalCache for symbols flagged as base-cached, so the measured 1.3 to 1.9 percent is the cost of one cache probe that the base path never pays.

The range is narrow across four runs, and the control arm behaves like the coin flip it should be, so the effect is small and real, not small and noisy. The range says nothing about how the cost behaves on code that does anything between calls. This case was built to make hashing look as bad as it can.

16.2.6 Limitations

This is one microbenchmark, built to stress function lookup. Real code computes between calls, so lookup is a smaller share of its time and the relative overhead of hashed lookup is probably lower.

Package-heavy workloads have not been tested. Package code makes many calls into base, but it also does more work per call, and I do not know which effect wins.

I did not measure the cost of writing to the base environment. SET_SYMVALUE on assignment is rarer than reading and this benchmark never exercises it.

I did not measure cache behavior. A hash probe touches different memory than a direct symbol read. If it causes more cache misses on real code, the overhead there could be higher than measured here.

One machine, WSL2, not the project’s own D7 benchmark harness. That environment cannot resolve one percent on absolute latencies. Pairing gets under that for a ratio, because both terms move together, but the number would not survive being quoted as an absolute. This is a ratio, and it is not a statement about how fast anything is.

The base case skips R_GlobalCache entirely, because base symbols carry BASE_SYM_CACHED, so the measured difference already includes losing that fast path. The design note that framed this measurement (docs/p4/symvalue-measurement.md) assumed both paths probe the cache first, which is not what findFun3 does in R 4.6.1; the conclusion survives, because the hashed path’s extra cost is still one probe. What the case does not exercise is package code, which finds base functions through the base namespace and not through the global cache; there a hashed base environment would pay a probe of its own frame.

16.2.7 Next experiment

threaded-r dropped the hashed base environment, so I have not run the follow-up measurements this page once listed: package workloads under the D7 harness, cache counters, writes to base, and other table designs. They would measure a design the fork does not use.

Where this appears

  • threaded-r Core measurement that validates whether per-interpreter base state is affordable.

Where to go next

Back to top