vile / bench / runtime / README.md
406 lines · 329 sloc · 21.13 KB · 76646891b77a3d5c6af4a1e42b122cd61dc1654b
Raw

Runtime comparison with Blip

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.

From the Vile repository root:

v -cc gcc run bench/compare_runtime.vsh 9 /path/to/blip

The launcher builds both runtimes into one executable with -cc gcc -prod, using the current V compiler. It prints the Blip checkout and revision; it uses that checkout's working-tree files. No source files in either runtime are changed. Blip's imports resolve through its vlib directory. The normal Vile toolchain, including the strings.Buffer addition used by the lexer, is required.

The four workloads use identical source accepted by both implementations:

call loads definitions before starting the clock, then invokes benchmark directly through each runtime's embedding API. eval measures parsing, definitions, and the same invocation together. Both exclude VM construction, source assembly, result extraction/checking, printing, and compilation. Neither loads a prelude or performs I/O.

Every sample creates a fresh VM. A full GC runs after setup and before the clock; allocation and GC during execution count. One full warm-up precedes each implementation/stage, then measurement order alternates. Reported times are medians. Every returned integer is checked explicitly even under -prod. Step/frame limits remain enabled with generous equal numeric limits, although the two machines count transitions differently.

This measures four shared integer workloads on one machine. It does not compare features outside that subset or measure steady-state memory use.

Toolchain compatibility for the measured upstream revision

Upstream Blip origin/main at 706360abde98d087be22635dc3cbd12acd078c5b uses usize in five expressions in vlib/blip/reader/mod.v. The local custom V 0.5.2 2f5d1e7 requires uint there. Measurements use a temporary checkout with only those five substitutions, matching the earlier front-end comparison. The Blip evaluator is unmodified. This launcher does not apply patches.

Initial syntax-tree evaluator baseline

Measured on Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz, with V V 0.5.2 2f5d1e7 and -cc gcc -prod. Blip upstream revision is the one documented above. Three runs of nine samples per implementation/stage; entries are medians of the three run medians. CPU busy before the runs was 14.2%, 7.8%, 6.0%.

Workload Stage Vile ms Blip ms Blip / Vile
tail-sum-10k call 26.685 86.694 3.25×
tail-sum-10k eval 26.163 71.391 2.73×
fib-20 call 48.410 621.057 12.83×
fib-20 eval 49.707 536.497 10.79×
closure-5k call 16.804 62.891 3.74×
closure-5k eval 16.585 60.278 3.63×
list-3k call 18.823 83.433 4.43×
list-3k eval 17.667 82.262 4.66×

Lower time is better; a ratio above one means Vile is faster in this workload. These tiny programs spend most of their time executing, so the parsing timings should not be inferred by subtracting the separately measured stages.

Compiled runtime with local slots

Same upstream Blip revision, compiler, flags, and CPU as above. Three runs of nine samples per implementation/stage, alternating implementation order within each run; entries are medians of the three run medians. CPU busy before these runs was 5.6%, 10.6%, 9.0%. eval includes Vile's compilation as well as parsing and execution.

Workload Stage Vile ms Blip ms Blip / Vile
tail-sum-10k call 6.102 89.742 14.71×
tail-sum-10k eval 6.262 78.724 12.57×
fib-20 call 13.345 630.393 47.24×
fib-20 eval 13.063 602.046 46.09×
closure-5k call 3.812 61.319 16.09×
closure-5k eval 4.288 59.703 13.92×
list-3k call 4.388 83.288 18.98×
list-3k eval 4.577 85.563 18.69×

Execution and allocation change from the initial runtime

A separate comparison builds the saved initial evaluator and the compiled runtime with the same -cc gcc -prod flags. Each sample loads definitions and performs one unmeasured call in a fresh VM, collects garbage, then times direct host calls. Three runs of nine samples per implementation; process order alternates across runs. Tables report medians of run medians. These warm-call measurements use a different setup from the fresh first-call Blip comparison above.

Allocated bytes come from Boehm's synchronized cumulative allocation counters, read outside the timer. They measure allocation traffic, including collector rounding, rather than peak live memory or process RSS. GC during execution is included. Compilation, source preparation, VM construction, and warm-up are excluded from both execution time and allocated bytes.

Workload Before ms After ms Speedup Before KiB After KiB Fewer allocated bytes
tail-sum-10k 27.952 6.533 4.28× 12348.9 1563.9 87.34%
fib-20 49.946 11.843 4.22× 25671.3 2741.6 89.32%
closure-5k 16.624 3.727 4.46× 10861.0 1406.4 87.05%
list-3k 18.600 4.395 4.23× 8723.0 1268.2 85.46%
length-10k 28.294 4.604 6.15× 102620.5 32.8 99.97%
string-10k 6.280 4.708 1.33× 11866.1 31.8 99.73%

The four original workloads run once per sample. length-10k performs 100 calls to a compiled procedure counting a previously constructed 10,000-element list. string-10k performs 100 calls counting the characters in λ😀 repeated 5,000 times. Their remaining allocations include the per-invocation embedding stack; the scans themselves do not allocate element or rune arrays.

The instruction VM still allocates environments and local-slot arrays for closure calls. These measurements do not establish bounded total allocation for tail-recursive programs.

Global-slot caching and activation reuse

The CLI's previous default of 1,000,000 steps aborted the 100,000-iteration sum loop with exit status 1 and no printed result. Its roughly 30 ms abort time was not a completed-program measurement. The CLI now defaults to unlimited steps and exposes --max-steps; embedding defaults are unchanged. All measurements below verify exit status and output. The old runtime baseline was rebuilt with the same unlimited CLI budget, compiler, and production flags.

A three-run cold-process comparison (31 samples/run at 0 and 100k iterations, 9 samples/run at 1M) measured the first optimized pass against that successful baseline and Guile 3.0.11:

Iterations Previous Vile ms Optimized Vile ms Guile ms
0 1.554 1.527 10.668
100,000 58.047 24.425 28.686
1,000,000 561.941 235.780 189.100

These include startup, parsing, preparation, execution, and output. A separate 51-sample comparison after bounding the activation cache measured 24.612 ms for Vile and 29.187 ms for Guile at 100k iterations. Zero iterations measured 1.371 ms and 10.919 ms. These figures do not establish faster steady-state execution than Guile; longer workloads still favor Guile in this comparison.

Peak RSS for the successful 100k program, from seven native wait4 samples, was a median 3.004 MiB for the final Vile build, 3.320 MiB for the successful previous-runtime baseline, and 12.301 MiB for Guile. Allocation traffic and peak RSS are different measurements.

For a repeatable checked cold-process comparison, from the repository root:

v -cc gcc -prod -o vile .
v -cc gcc run bench/compare_guile.vsh --samples 31 --iterations 100000

The runner includes a zero-iteration case and rejects both unsuccessful exits and incorrect sums. --vile and --guile select executable paths.

The final cache reuses at most 32 unescaped activations with 0..7 slots, grouped by slot count. It clears old values before caching; captured environments are excluded. In a nine-sample warm direct-call check, allocation traffic was:

Workload Final allocated KiB per measured workload
Tail sum, 100k 0.859
Fibonacci(20) 7.969
Captured adder loop, 5k 3.000
Build/traverse 3k pairs 234.844

The same earlier cache-with-one-entry pass allocated 1,545.5 KiB on Fibonacci; the bounded cache retains enough retired activations to reuse them across the recursive branches. The previous runtime allocated 15,625.6 KiB on the 100k tail sum. Escaping closures and actual pair construction still allocate as needed. The bounded cache adds a small fixed amount of metadata per machine invocation; short host-call workloads can therefore allocate slightly more metadata.

Compact values and the data library

The next pass stores the integer, float, and pointer alternatives in one union. Value shrinks from 32 to 16 bytes and a pair payload from 64 to 32 bytes on this 64-bit build. Pointer members remain ordinary GC-visible pointers, and generated C confirms that value arrays use scanned allocations. This is independent of the instruction width, which remains 16 bytes.

With the same data library and -cc gcc -prod build flags, a checked cold-process comparison measured the following medians. One warm-up, alternating order, 31 samples at 0/100k iterations and 9 at 1M; Guile 3.0.11 on the same machine. CPU utilization before the run was 6%.

Sum-loop iterations 32-byte values ms 16-byte values ms Guile ms
0 1.620 1.621 11.031
100,000 25.781 19.811 29.265
1,000,000 240.471 189.297 188.992

The 100k program is about 23% faster with compact values. The 1M comparison is approximately tied with Guile in this run; this is not a general claim about Scheme workloads or Guile's steady-state performance.

In three alternating runs of nine warm-call samples, building/traversing 3,000 pairs allocated a median 241,872 bytes with 32-byte values and 145,296 bytes with 16-byte values, about 40% less. These are allocation-counter measurements with collector rounding, not live-object sizes or peak RSS. Short workloads can fall within the collector's allocation-counter granularity.

The data library also caches each string's character count. string-length no longer scans UTF-8. ASCII indexing and replacement have direct paths; changing a character's UTF-8 width copies the owned buffer once. Quasiquote leaves static suffixes constant, emits one instruction for a long static prefix, and fills spliced vectors directly rather than building temporary pairs.

After adding the numeric library and exact mixed comparisons, another checked run measured the current build as follows (31 samples at 0/100k, 9 at 1M, alternating order, medians; CPU utilization before the run was 6.3%):

Sum-loop iterations Current Vile ms Guile ms
0 1.633 10.682
100,000 21.170 29.265
1,000,000 198.126 186.237

The simultaneously measured earlier compact build took 20.195/195.115 ms at 100k/1M. The numeric pass adds about 0.03 ms of startup in this run; execution also varies by a few percent across these builds and measurements. Longer loops still favor Guile. Seven native wait4 RSS samples for the current successful 100k program had medians of 3,288 KiB for Vile and 12,528 KiB for Guile.

The numeric checks include 1,582 independent exact-rational/IEEE-754 comparison and conversion cases, plus quotient/remainder laws, exhaustive small rounding and rationalization intervals, GC retention, and sanitizer builds. The fixture can be regenerated with python3 scheme/testdata/generate_mixed_numbers.py; normal V test runs use the stored fixture and need no Python.

Control operations and the owned operand stack

The runtime now includes multiple values, continuations, map/for-each, promises, and dynamic-wind. Capture analysis also avoids unused enclosing environments and shares procedures that need no enclosing bindings. Compiled functions retain a slot count rather than a redundant array of local names.

Sampling the integer loop after these additions attributed about 28% of samples to V's generic array push. The VM now writes a value directly into spare capacity in its privately owned operand stack, using ordinary array growth when necessary. Native argument views remain borrowed for the duration of a call; reentry uses another machine, and continuation snapshots own copies of live stack prefixes. Non-tail primitive results replace the callable's existing slot rather than clearing that slot and pushing another value. Argument slots are still cleared.

A checked cold-process comparison with the same compiler and production flags measured these medians (31 samples at 0/100k, 9 at 1M, alternating order; CPU utilization before measurement was 7.5%):

Sum-loop iterations Saved numeric build ms Current Vile ms Guile ms
0 1.615 1.644 10.842
100,000 21.273 15.673 29.359
1,000,000 196.522 144.768 187.570

The current build is about 26% faster than the saved numeric build at 1M iterations despite the additional language operations. This remains a comparison of one integer loop, including process startup, rather than a claim about all Scheme programs. Every process exit and printed sum was checked.

Seven native wait4 samples of the successful 100k program measured median peak RSS of 3,332 KiB for this Vile build and 12,712 KiB for Guile. The low memory footprint is retained; these figures describe peak resident memory, not total allocation traffic.

dynamic-wind transitions prepare pending entry callbacks once on the existing operand stack. This avoids repeatedly traversing the extent chain, making a jump linear in nesting depth without a separate path array. A separate algorithm comparison, before the later operand-stack improvements, measured:

Nested extents Repeated traversal ms Linear transition ms
1,000 6.842 3.347
2,000 20.906 4.941
4,000 75.502 8.572
8,000 294.970 14.628

Each program enters and returns normally, then reenters its saved continuation and returns again; the expected total callback count is checked. These are seven-sample medians with one unmeasured warm-up and include process startup.

After adding numeric string conversions and checked literal range handling, another alternating run measured 16.145 ms at 100k and 149.744 ms at 1M, versus 29.575/187.676 ms for Guile. The simultaneously measured control build took 15.600/144.651 ms. Startup measured 1.673 ms versus 1.629 ms for that control build and 10.655 ms for Guile. Sampling counts were 31 at 0/100k and 9 at 1M; CPU utilization before the run was 5.5%.

Median peak RSS from seven checked native samples was 3,356 KiB for the numeric I/O build and 12,784 KiB for Guile. Temporary large-number arithmetic is used for written fractions needing reduction and for exact rounding of long inexact inputs; ordinary bounded integer literals avoid that path.

After adding hygienic syntax-rules, local syntax bindings, and macro-generated definition groups, another checked alternating run measured:

Sum-loop iterations Numeric I/O build ms Syntax build ms Guile ms
0 1.652 1.701 10.721
100,000 16.064 16.008 29.343
1,000,000 150.477 143.212 191.264

These are medians of 31 samples at 0/100k and 15 samples at 1M, after one unmeasured warm-up. CPU utilization before measurement was 7.6%. Both Vile binaries used GCC production builds; each exit status and result was verified. The small differences between adjacent Vile builds depend on generated code layout and measurement conditions. They do not establish a general speedup from adding macros.

Seven native wait4 samples at 1M iterations measured median peak RSS of 3,428 KiB for the numeric I/O build, 3,380 KiB for the syntax build, and 12,704 KiB for Guile. Replacing the loop's if with a syntax-rules macro measured 3,396 KiB. This retains the roughly 3.3 MiB footprint on this workload; small RSS differences should not be treated as allocation reductions.

Macro expansion emits ordinary instructions. A regression test compares the executable instructions and constants for direct and macro-expanded versions of the tail loop, then executes both for 100k iterations. Generated syntax uses 16-byte scratch cells; frozen transformer trees use 12-byte cells. Instruction locations resolve to original source IDs during emission, allowing all generated AST storage to be discarded after compilation. Literal-only repeated patterns do not allocate capture coordinates. The additional syntax-install instruction is appended to the opcode enumeration, preserving existing instruction numbers.

Validation includes 29 runtime/public test files, assertion-enabled GCC -O3 tests, address/undefined-behavior sanitizer runs with Boehm and without GC, and 201 comparisons with Guile covering nested repetitions and invalid dimensions. One Guile oracle alpha-renames _, which Guile reserves as a wildcard while R5RS treats it as an ordinary pattern variable.

After adding ports and file controllers, instruction dispatch separates common operations from compound construction/control setup. A monolithic candidate crossed GCC's inlining threshold and regressed substantially; it was discarded. The retained common dispatcher is inlined, while the extended handler remains a separate function. No extra dispatch call is paid by ordinary loop instructions. An alternating checked run after this correction measured:

Sum-loop iterations Previous syntax build ms Ports build ms Guile ms
0 1.699 1.724 11.113
100,000 15.495 14.399 29.412
1,000,000 139.956 129.086 189.858

These are 31-sample medians at 0/100k and 15-sample medians at 1M, with one warm-up, alternating implementation order, verified answers, and 8.5% CPU utilization before measurement. Seven native wait4 samples at 1M measured median peak RSS of 3,452 KiB for the previous build, 3,552 KiB for ports, and 12,628 KiB for Guile. A broader nine-sample checked comparison improved tail sums, Fibonacci, closure calls, pair traversal, case, quasiquote, and multiple values; map was about 2% slower. These results describe this build/workload rather than a general performance guarantee. Port data input and output have separate benchmark harnesses in bench/ports and bench/port_output.

The completed required runtime adds Scheme eval, immutable report/null environments, a mutable interaction environment, and exact integer overflow recovery for variadic cancellation and zero/sign changes. eval enters compiled datum code on the same machine through a private bytecode bridge; it preserves proper tail calls, surrounding continuations, values and dynamic extents. Name resolution stays in a cold helper; cached global reads use absolute slots.

A checked alternating comparison of the final GCC production binary measured:

Sum-loop iterations Installed ports baseline ms Final runtime ms Guile ms
0 1.683 1.724 10.825
100,000 14.966 14.405 29.444
1,000,000 127.326 132.192 192.773

CPU utilization before measurement was 4.5%. Counts remain 31 samples at 0/100k and 15 at 1M, after one warm-up, with every exit status and sum checked. Adjacent build differences include code layout effects; adding features does not promise a universal speedup. Seven native wait4 samples at 1M measured median peak RSS of 3,532 KiB for ports, 3,548 KiB for the final runtime, and 12,572 KiB for Guile.

Validation includes 36 runtime/public test files, optimized assertion-enabled tests, address/undefined-behavior sanitizers with and without GC, 97 eval comparisons with Guile, 184 independent Scheme examples, all 188 required procedure bindings for the supported real numeric tower, and 450 arbitrary- integer oracle cases. The existing macro and numeric I/O fixtures also run. The runtime keeps bounded real numeric representations; general complex numbers and optional loading/transcript procedures are outside the implemented set.