Native execution
The optional native backend accelerates repeated integer, floating-point, list and borrowed-vector work, including checked n-ary arithmetic and integer division families. Vector writes use rollback before interpreter replay. It currently targets hosted macOS C builds. Use the project's V toolchain and Clang. Ordinary builds keep the existing interpreter and platform support.
Build the native CLI on macOS with the V revision in the build instructions.
export VJOBS=1 VFLAGS=-no-parallel MAKEFLAGS=-j1
v -no-parallel -cc clang -prod -d vile_native -o vile-native main.v
./vile-native --native program.scm
./vile-native --native program.vile
--native compiles eligible bytecode graphs on first use and caches the compiled
images across invocations. Clang adds first-call cost on a cache miss. Prepared
timings exclude that compilation cost; first-call and whole-process durations
are recorded separately. Running without --native uses the interpreter.
The cache lives at $XDG_CACHE_HOME/vile/native-v1 or
~/.cache/vile/native-v1. Set VILE_NATIVE_CACHE=/private/path to select another
root, or VILE_NATIVE_CACHE=off to compile without persistence. The directory
must belong to the current user and allow no group/other access; unusable caches
fall back to ordinary compilation. Corrupt or incompatible entries are rebuilt.
Custom CPATH, C_INCLUDE_PATH, CPLUS_INCLUDE_PATH, OBJC_INCLUDE_PATH or
SDKROOT settings disable persistent reuse because their header contents are
opaque dependencies. The cache has no automatic eviction; remove its directory
when no process is using it to reclaim disk space.
Cache entries contain compiled code only. Keys include generated source and ABI, compiler/version, platform, flags and compiler environment. Each invocation reconstructs guards and reads current captured values; captured environments and VM pointers are never serialized. Files are hash-verified before loading and published atomically. Dynamic-library handles still close with their host scope.
Embedding hosts can build with -d vile_native and wrap synchronous work in
vm.with_native_execution(work), using the existing scheme.EvaluationFn
signature. Set Options.max_steps and Options.max_frames to zero to enable
native execution. Scopes close their code handles and free their private arenas
on return or error. CLI exits also close the scope before terminating.
Step/frame limits, bounded VMs, cancellation and arena-usage controls, explicit file/compiler budgets, and borrowed allocation owners use the interpreter. Unsupported graphs also use the interpreter, preserving the shared language. Arguments, captures and active allocation/control rules are checked at entry. Successful global binding, owner and primitive-protocol checks are reused until global replacement, primitive-generic installation/reset, binding-topology changes or syntax-declaration changes invalidate them. Revision wrap invalidates plans; saturated syntax generations use the complete checks. Existing closure arguments and captured procedures can join the native graph. Each provider checks its live owner and function identity; captured procedure cells also check the selected provider's exact closure identity on every entry. Closures sharing code retain their separate environments. Capture buffers are reused within the synchronous native scope.
Unchanged procedure parameters can call their guarded provider directly. Native function entries recheck the selected procedure ID on internal calls and self tail jumps. Assigning a procedure parameter keeps dynamic dispatch.
Immediate binding helpers, including eligible let, let* and empty scopes,
can lower to private native locals after proving their closure values cannot
escape. Arguments keep their evaluation order, internal definitions start
uninitialized on every helper call, and tail calls keep their enclosing context.
Escaping closures, continuations and unsupported helper bodies use the VM.
The original bytecode remains available for replay.
Immediate private call-with-values callbacks can also lower to locals and
jumps, with zero through eight explicit values or an ordinary scalar producer.
The compiler proves that callback and builtin operator values stay private;
entry guards check actual bindings and the internal control bridge. Nested calls
retain pending work, internal definitions reset per activation, and unsupported
control or escaping values use the VM. No per-iteration callback closure or
multiple-value bundle is needed on the eligible native path.
Private zero-argument dynamic-wind callbacks can also lower to native locals
when the compiler proves their values stay private and no operation can observe
or escape the extent. Guards check the exact existing control bridge. The body
result survives the after callback, and private recursion cannot skip after.
Unsupported protocols, continuations and host reentry keep VM execution. Native
failure rolls speculative mutations back before the VM runs the original call.
Eligible named loops inside these callers also flatten to private locals and backward jumps, with internal definitions reset on every iteration. Loops in callers that receive procedures, and standalone compiler wrappers, retain the smaller existing loop-body entry. Escaped or rebound loop procedures and non-tail private recursion use the VM.
Existing integer, real, boolean, empty-list and unspecified captured bindings can be updated through staged scalar cells. Tiny straight-line mutator roots stay on the VM path; the same helpers can run inside larger native graphs or loops. Reads and writes sharing one lexical cell share one staged value, and every entry checks alias relationships involving writable cells. Read-only providers remain independent when their sharing changes. The VM cells stay unchanged until the result and every pending value validate. Success commits all scalar cells; failure discards them and restores vector writes before replay. Captured procedure, vector and private-pair stores use the interpreter. Borrowed cell handles are cleared on every exit.
Vile bare-name expressions retain their data-value or implicit zero-argument call behavior in eligible graphs, including tail calls and binding helpers.
Existing proper integer lists can enter native graphs through arguments,
globals and captures. A bounded import copies them into the existing arena
pair pool; source pairs remain unchanged. Imports and private cons share
4,096 cells. Malformed, cyclic, oversized and non-integer lists use the VM.
A failed import prevents further pair imports for that plan in the current
scope, avoiding repeated copies during VM tail recursion; scalar and nil calls
remain eligible. Graphs that do not read list contents skip these imports.
Returning or storing a private list replays the original VM call, preserving
the original list or tail identity. Vector reads of pair values keep using the VM.
Overflow, unsupported results and private-pool/depth exhaustion replay the call through the interpreter. Private pairs cannot escape as Scheme values or be stored in existing host vectors. Journaled writes are restored before replay. An executed native call that falls back disables its plan until the scope ends, so recursive replay performs the failed speculation once. Disabled plans return to the VM before checking arguments again. Native execution requires an unlimited VM; it adds no instruction ceiling of its own. Configured VM budgets and host controls continue to use the interpreter.
Binary64 literals, captures, arguments and results stay scalar. Mixed integer/real comparisons preserve exact integer boundaries. Arithmetic follows the VM’s fold order and disables multiply/add contraction. Integral inexact-to-exact results within signed 64-bit bounds run natively; fractions, larger exact results and nonfinite conversion errors use the existing interpreter fallback. Native division/remainder operations still require integer arguments.
Borrowed vectors support indexed reads, length and writes, including nested vectors and live scalar/vector globals. Readonly flags and bounds remain checked. A first-touch journal keeps original handles in the invocation’s C stack frame, visible to the collector. Repeated writes to one cell share an entry; exceeding 1,024 changed cells restores the destinations and uses the VM. Original handles are cleared after commit or rollback. Vector constructors and opaque contents still require the interpreter; native subcalls can accelerate eligible parts of those programs. Native vector operations add no heap allocation or new GC dependency.
Borrowed bytevectors support length, unsigned byte reads and byte writes through the same callback and journal. Indexes and byte values must be exact integers; byte values stay in 0..255. Bytes and vector cells share the 1,024-cell transaction budget, with repeated writes to one destination sharing an entry. Failure restores both sequence kinds before VM replay. Returned handles and vector publication preserve bytevector identity and readonly flags. Captured bytevector stores use the VM. Byte-only graphs keep integer specialization; no per-byte allocation or larger fixed journal is required.
Compilation scratch and pair pools use owned arenas. Pair-free graphs allocate
no execution arena storage; the vector journal uses a bounded stack frame. Plans retain code identities and binding/capture selectors
within the host scope; captured procedures/environments stay outside persistent
caches. vm.native_execution_stats() reports successful native invocations and
executed native calls that fell back. Binding/eligibility rejections are excluded
from those counters.
vm.native_compilation_stats() reports verified disk-cache hits and source
compilation attempts in the current scope; compiler-version queries are excluded.
The shared comparison has 24 workloads: the original four integer kernels,
flonums, bignums, exact rationals, division/remainders, lists, vectors,
bytevectors, hashtables, ASCII/Unicode strings, datum ports, mutable closures,
higher-order calls, continuations, multiple values, dynamic winding, and GOOPS
inherited dispatch and allocation. The timed definitions and batch loop are
identical in both engines. Per-engine imports provide the same APIs before timing.
Suite v3 varies work sizes or input ranges across four seeds. Independent
per-seed integer checksums and source hashes are recorded in cases.json;
catalog.py checks those oracles. A separate scaling gate rejects batches that
optimize the repeated work away.
An additional mock window-manager suite has twelve headless
workloads covering callbacks, dispatch, layouts, lifecycle, hooks, macro DSLs,
source loading and live reloads. Select it with --suite wm on every harness
phase. Its results remain separate from the 24-case runtime suite.
The five variants are ordinary interpreter and opt-in native execution, each with
arena allocation and Boehm GC, plus Guile 3.0 (guild compile -O2, default JIT).
Cases that stay in the interpreter remain in the results. Native invocation and
deoptimization counters show observed activity; they do not measure the fraction
of instructions compiled. No speed threshold or native-hit requirement filters
which workloads appear.
Each process performs five untimed calls, then a per-case checked batch. The first call is timed separately. Counts are identical across variants for each case; the original four retain their 100-call batches. The harness rotates 31 measured samples after one excluded process warmup, records median/IQR/range, and includes all cases in category and unweighted geometric-mean summaries. Whole-process durations include setup, warmup, compilation, measured work and cleanup; they are separate from prepared execution.
Run the phases separately under the shared lock on the idle Mac:
python3 bench/native/compare.py build
python3 bench/native/compare.py verify
python3 bench/native/compare.py scaling
# After builds and verification finish and the Mac is idle:
python3 bench/native/compare.py measure
The harness defaults to --native-cache off so first-call measurements include
compilation. Use --native-cache reuse --output native-results-cached on every
phase for a separate populated-cache comparison. Verification populates that
isolated cache before measurement. Keep compiler/header environment settings
consistent across phases; the recorded cache and compilation counters show
actual reuse. Unsupported graphs and cache fallbacks remain in the results.
Set VEXE, GUILE, and GUILD when the tools are outside PATH. The harness
verifies source/tool/binary hashes, checks every result explicitly under -prod,
and preserves completed build jobs and samples for resumption. Results, raw
samples, flags and timing boundaries are written to native-results-v3/.
Measured results and timing boundaries are in bench/native/RESULTS.md.
Compiled-code cache measurements and limitations are in bench/native/CACHE-349.md.
Native fallback dispatch measurements are in bench/native/DISPATCH-350.md.
Retained integer/floating-point measurements are in bench/native/NUMERIC-352.md.
Retained native-vector and binding-guard measurements, including both full suites and remaining regressions, are in bench/native/GUARDS-358.md.
The complete existing-callback and binding-helper comparison is in bench/native/BINDINGS-360.md. It includes all 36 workloads and both collectors; the full 1.5× advantage over Guile remains unmet.
The staged-capture comparison is in bench/native/CAPTURES-361.md, including the entry cost policy, read-only provider alias regression, both collectors and all 36 workloads.
The private-loop comparison is in bench/native/LOOPS-362.md. Private named loops improve native GC WM performance 1.31× and runtime performance 1.07× over retained361. All 101 native cases passed under ASan/UBSan and Boehm, alongside CLI/default checks and both production builds. All 36 workloads, earlier trial regressions and remaining losses are included. Guile still leads both suites; the requested 1.5× advantage remains unmet.
The borrowed-list comparison is in bench/native/PAIRS-363.md. Borrowed integer-list inputs improve the runtime suite 1.10× over retained362; the WM aggregate changes by less than 1%. All 114 native tests passed under ASan/UBSan and Boehm, alongside CLI/default checks, both production builds, all 36 workloads and 28 scaling groups. No workload regressed by more than 5%. Guile still leads both suites; the requested 1.5× advantage remains unmet.
The borrowed-bytevector comparison is in bench/native/BYTES-364.md. Borrowed bytevectors improve the runtime suite 1.13× over retained363; the WM aggregate is essentially unchanged. All 129 native tests passed under ASan/UBSan and Boehm, alongside CLI/default checks, both production builds, all 36 workloads and 30 scaling groups. No workload regressed by more than 5%. Guile still leads both suites; the requested 1.5× advantage remains unmet.
The earlier multiple-value comparison is in bench/native/VALUES-365.md. Private multiple-value callbacks improve the native GC runtime suite 1.29× over retained364; WM gain is 1.002×. All 147 native cases pass under ASan/UBSan and Boehm, with CLI/default checks and both production builds. All 36 workloads, 32 scaling groups, first-call observations and losses are included. Guile leads by 1.06× on runtime; Guile leads by 2.28× on WM. The requested full 1.5× advantage remains unmet.
Ordinary-interpreter operand fusion is measured separately in bench/runtime/FUSION-366.md. With native execution disabled, the GC interpreter gains 1.134× across all 36 workloads versus365. This preserves virtual step counts, precise instruction-limit boundaries and original bytecode. Guile still leads this interpreter aggregate by 7.29×; the 1.5× goal remains unmet.
Ordinary fixed-arity closure entry is measured separately in bench/runtime/CALLS-367.md. With native execution disabled, the GC interpreter gains 1.073× across all 36 workloads versus366. This preserves virtual step counts, precise instruction-limit boundaries and original bytecode. Guile still leads this interpreter aggregate by 6.79×; the 1.5× goal remains unmet.
Ordinary primitive reads are measured separately in bench/runtime/READS-368.md. With native execution disabled, the GC interpreter gains 1.033× across all 36 workloads versus 367. This preserves virtual step counts, precise instruction-limit boundaries and original bytecode. Guile still leads this interpreter aggregate by 6.59×; the 1.5× goal remains unmet.
Parameterized scopes and map entry are measured separately in bench/runtime/SCOPES-369.md. With native execution disabled, the GC interpreter gains 1.050× across all 36 workloads versus 368. Existing instructions carry the scope argument count while virtual steps and precise instruction-limit boundaries remain unchanged. Guile still leads by 6.27×; the 1.5× goal remains unmet.
Primitive-result branches are measured separately in bench/runtime/BRANCHES-370.md. With native execution disabled, the GC interpreter gains 1.018× across all 36 workloads versus 369. Branch fusion preserves virtual steps and precise instruction-limit boundaries. Guile still leads by 6.15×; the 1.5× goal remains unmet.
The earlier conversion comparison is MARSHAL-374.md. Direct value conversion changes native GC performance 1.036× overall versus retained370/native373; WM gain is 1.078×. Guile leads by 1.26× across all 36 workloads. All 151 native/fallback cases pass under ASan/UBSan and Boehm, plus CLI/default checks. The ordinary interpreter remains measured separately in BRANCHES-370.md. The full 1.5× goal remains unproven; all workloads and losses are included.
The equality comparisons for both engines are in EQUALITY-375.md. GC WM gains are 1.128× interpreted and 1.136× native. Guile leads by 5.92× across the interpreter suite; Guile leads by 1.21× with native execution. All 36 workloads, both collectors and losses remain included. The full 1.5× goal is still unproven.
The earlier native text comparison is TEXT-376.md. Native text reads gain 1.101x overall versus 375; Guile leads by 1.10x across all 36. All workloads, both collectors and losses remain included. That update kept interpreted execution at the separately measured 375 result. The full 1.5x goal remained unproven.
The latest comparison for both engines is BUDGET-401.md: all 36 workloads, both collectors and 31 retained rounds versus 400. Their unlimited-step aggregate is essentially unchanged: interpreted GC is 0.1% slower and arenas 0.1% faster. Native estimates are within 0.1% of 400, with intervals including parity. No individual case exceeds 5% elapsed regression in this pass; every measured loss remains included.
A separate comparison of the original values workload with the default one-million-step budget improves by 1.396x with GC and 1.250x with arenas. Private forwarding now works when at least two instruction charges remain; near-limit boundaries retain the packet path. This single-case result is kept outside the 36-workload aggregate.
Guile still leads interpreted Vile by about 5x overall. Native Vile leads Guile by 1.155x with GC and 1.173x with arenas. The full 1.5x goal remains unmet. Previous comparison: VALUES-400.md, including its known continuation/loop and native regressions. R7RS compatibility and smoke timings remain separate; no full R7RS performance aggregate is claimed.