vile / bench / runtime / LOOPS-391.md
129 lines · 108 sloc · 11.44 KB · 76646891b77a3d5c6af4a1e42b122cd61dc1654b
Raw

Integer recurrence execution at cached closure entry (391)

The interpreter recognizes a small, guarded two-parameter integer recurrence and executes its complete iterations at the existing cached closure-entry transition. It keeps the original bytecode and falls back before unsupported operands, rebinding, overflow, escaped environments, controls, allocation ownership or incomplete instruction budgets require the VM. Every complete iteration retains all 19 virtual instruction/application charges. No per-call plan allocation, native code, new GC dependency or compiler/standard-library change is involved.

Compilation admits only already resolved, owned primitive comparison and arithmetic operators. Runtime checks still read their live values. Arbitrary closures, cons and unresolved or hygienic fallback bindings retain ordinary execution. The optional native backend retains first refusal, and controlled/single-step loops retain their original execution. Scalar parameters and charges commit once after a successful prefix; both updates read the old parameters.

The earlier header-dispatch trial (390) is not retained: although two loops improved, higher-order calls and list/string construction regressed substantially. This revision restores the common dispatcher byte for byte, filters unsupported operators at compilation, and runs the recurrence after the normal closure transition. The common dispatcher source is byte-identical to retained389. All four production C recurrence loops have zero generic array_get/array_set calls and no heap allocation or VM dispatch/application/activation. Actual C and assembly are archived; checked arithmetic update leaves remain outlined.

Assembly diagnostic correction (393): the original label-delimited otool span for Machine.run extends beyond its true symbol boundary after embedded jump-table bytes. Its 3,172/3,173 instruction totals and span-based generic-call counts are withdrawn. Exact C recurrence audits and all benchmark observations, ratios and losses above/below are unchanged. Corrected audits use nm symbol ranges and symbol-specific LLVM disassembly; instruction counts require a complete control-flow graph. The original archive report is preserved with an AUDIT-CORRECTION-393.json addendum.

All 22 focused cases pass in both engine builds under ASan/UBSan and Boehm. They cover parallel updates, comparison polarity, live operator/self rebinding, overflow promotion, exact budgets and error positions, continuation/GC replay, captured locations, foreign owners, cancellation, bounded arenas, source syntax and fallback admission. The unchanged 390 baseline passes semantic results but fails four new performance/admission probes as expected; one rebinding case passes. The final source passes 410 ordinary and 339 native cases per sanitizer/Boehm mode, plus two CLI cases and the default-build budget check.

Both complete comparisons use the same idle Intel Mac mini, Guile 3.0.10 (guild -O2/default JIT), all 24 runtime and 12 mock-WM workloads, both collectors, frozen four-input oracles, unchanged batches and five warmups. Each engine has 5,760 observations: 31 retained process rounds per case/configuration plus uniformly excluded sample zero. Preparation is separate (144 cold observations per engine), warmup/measured compilation is zero, and ordinary native/JIT counters are zero. All 46 scaling groups per engine pass 4 versus 400 calls with at least 20x elapsed growth. All 4,608 paired native hit/deopt observations match the baselines. Builds, tests, preparation, analysis and timing run separately and serially from hash-verified snapshots under the shared Mac lock.

This revision is retained for its interpreted gain, with the native losses below explicitly included. Ratios above one favor candidate or Vile, respectively; aggregates are equal-weight geometric means over every workload. Interpreted comparisons use retained 387; native comparisons use retained 389. R7RS compatibility/first-use results remain separate, with no full R7RS timing aggregate claimed. The full 1.5x goal remains unmet: Guile is about 5.2x faster than interpreted Vile across all 36 workloads.

Engine Suite GC gain Arena gain Guile/Vile GC Guile/Vile arena
interpreter wm 0.993x 0.990x 0.263x 0.258x
interpreter runtime 1.166x 1.159x 0.164x 0.160x
interpreter all36 1.105x 1.099x 0.192x 0.188x
native wm 0.988x 1.000x 0.639x 0.637x
native runtime 0.990x 0.998x 1.515x 1.569x
native all36 0.989x 0.999x 1.136x 1.162x

Interpreted tail-sum improves 6.23x with GC and 6.29x with arenas; the numeric loop inside call/cc escape improves 5.86x and 5.60x. Higher-order, list-building and string-building losses from the rejected 390 trial are gone. No interpreted workload/collector loses more than 5%.

Native GC loses 1.1% overall. Its list-map and string-scan workloads lose 8.8% and 9.7%, respectively. These losses remain in every aggregate; native pure-kernel decisions and hit/deopt counts are unchanged. Further investigation is required before attributing the losses to a particular layout or compiler effect.

95% paired-round percentile bootstrap intervals use 2,000 deterministic resamples within each fixed workload (seed 390031). They estimate observed process variation, not performance on unseen programs. Primary medians and weights are unchanged.

Engine GC gain interval Arena gain interval Guile/Vile GC interval Guile/Vile arena interval
interpreter 1.1042–1.1061x 1.0981–1.1004x 0.1922–0.1928x 0.1876–0.1882x
native 0.9884–0.9940x 0.9975–1.0005x 1.1354–1.1391x 1.1609–1.1648x

interpreter / wm

Workload Baseline GC ms 391 GC ms Guile ms GC gain Arena gain
wm-callback-chain 4.545002 4.535935 0.638000 1.002x 0.989x
wm-config-load-tree 4.959661 4.979626 8.988250 0.996x 0.998x
wm-event-dispatch 2.782636 2.786823 0.215000 0.998x 0.976x
wm-focus-cycle 4.059424 4.118218 0.380250 0.986x 0.982x
wm-hooks 2.738227 2.751439 0.357000 0.995x 0.990x
wm-keybindings 1.141828 1.128536 0.280250 1.012x 1.003x
wm-lifecycle 0.966797 0.982507 0.126750 0.984x 0.990x
wm-macro-config 4.444025 4.480553 5.284500 0.992x 1.004x
wm-reload-live 7.050649 7.105261 8.150000 0.992x 0.989x
wm-session-replay 6.432977 6.471097 8.055250 0.994x 0.994x
wm-tiling-layout 1.753244 1.758960 0.108750 0.997x 0.970x
wm-workspace-move 1.206436 1.241579 0.173750 0.972x 0.988x

interpreter / runtime

Workload Baseline GC ms 391 GC ms Guile ms GC gain Arena gain
bignum-fib-200 0.033089 0.033152 0.005417 0.998x 1.002x
bytevector-fill-4k 0.748100 0.767267 0.086167 0.975x 1.005x
callcc-escape-1k 0.068639 0.011708 0.006667 5.862x 5.603x
closure-5k 0.491242 0.510586 0.015560 0.962x 1.005x
closure-mutate-2k 0.273652 0.276873 0.008500 0.988x 0.990x
datum-read-write-200 1.213022 1.197874 2.281625 1.013x 0.995x
dynamic-wind-200 0.127308 0.124810 0.012583 1.020x 0.998x
fib-20 4.447353 4.494250 0.310760 0.990x 0.986x
flonum-sum-2k 0.486891 0.472142 0.095833 1.031x 0.999x
goops-allocate-200 0.081231 0.080847 0.054750 1.005x 0.996x
goops-dispatch-1k 0.744082 0.737386 0.109000 1.009x 0.995x
hashtable-count-1k 0.431168 0.432915 5.976167 0.996x 1.001x
higher-order-2k 0.351445 0.352453 0.006333 0.997x 1.005x
integer-divmod-5k 0.816941 0.835517 0.168083 0.978x 0.999x
list-3k 0.892183 0.869653 0.059870 1.026x 0.988x
list-map-1k 0.110114 0.108601 0.048667 1.014x 1.091x
list-reverse-2k 0.463985 0.431340 0.060750 1.076x 0.986x
rational-harmonic-80 0.094934 0.094874 0.049625 1.001x 1.005x
string-build-1k 0.041140 0.041140 0.042917 1.000x 1.004x
string-scan-4k 0.632962 0.616512 0.043750 1.027x 0.982x
tail-sum-10k 0.662391 0.106403 0.033680 6.225x 6.289x
unicode-scan-1k 0.170868 0.168011 0.011750 1.017x 0.976x
values-consumer-1k 0.595639 0.599086 0.004417 0.994x 0.998x
vector-update-2k 0.368129 0.379652 0.016167 0.970x 0.978x

native / wm

Workload Baseline GC ms 391 GC ms Guile ms GC gain Arena gain
wm-callback-chain 0.475611 0.480620 0.640500 0.990x 0.998x
wm-config-load-tree 4.663806 4.653842 8.965000 1.002x 1.018x
wm-event-dispatch 0.809856 0.826604 0.215250 0.980x 0.991x
wm-focus-cycle 0.472967 0.482424 0.378500 0.980x 1.001x
wm-hooks 2.049854 2.082264 0.355000 0.984x 1.003x
wm-keybindings 0.944670 0.954292 0.280750 0.990x 0.995x
wm-lifecycle 0.872991 0.877578 0.125250 0.995x 0.977x
wm-macro-config 4.398073 4.433939 5.308250 0.992x 0.996x
wm-reload-live 4.815481 4.840649 8.132750 0.995x 0.999x
wm-session-replay 4.865709 4.907478 8.103000 0.991x 1.010x
wm-tiling-layout 0.258782 0.265653 0.109000 0.974x 1.007x
wm-workspace-move 0.189680 0.192079 0.174000 0.988x 1.001x

native / runtime

Workload Baseline GC ms 391 GC ms Guile ms GC gain Arena gain
bignum-fib-200 0.042993 0.042959 0.005417 1.001x 0.998x
bytevector-fill-4k 0.083463 0.080713 0.086167 1.034x 0.988x
callcc-escape-1k 0.094332 0.094650 0.006667 0.997x 0.978x
closure-5k 0.002130 0.002128 0.015590 1.001x 1.000x
closure-mutate-2k 0.002828 0.002868 0.008417 0.986x 1.003x
datum-read-write-200 1.578333 1.584568 2.258500 0.996x 0.997x
dynamic-wind-200 0.000428 0.000429 0.012667 0.997x 1.001x
fib-20 0.146947 0.146913 0.310940 1.000x 0.998x
flonum-sum-2k 0.002376 0.002376 0.095833 1.000x 0.999x
goops-allocate-200 0.085720 0.086395 0.054875 0.992x 0.993x
goops-dispatch-1k 0.782952 0.791735 0.110500 0.989x 1.001x
hashtable-count-1k 0.461891 0.459220 5.970917 1.006x 0.989x
higher-order-2k 0.004077 0.004071 0.006333 1.001x 1.000x
integer-divmod-5k 0.007920 0.007930 0.168167 0.999x 1.000x
list-3k 0.007197 0.007205 0.060020 0.999x 0.999x
list-map-1k 0.125688 0.136794 0.048500 0.919x 0.995x
list-reverse-2k 0.066658 0.067642 0.060833 0.985x 0.989x
rational-harmonic-80 0.104023 0.105889 0.049250 0.982x 1.000x
string-build-1k 0.045705 0.045022 0.042833 1.015x 1.002x
string-scan-4k 0.089621 0.098319 0.043750 0.912x 1.024x
tail-sum-10k 0.005607 0.005608 0.033700 1.000x 1.000x
unicode-scan-1k 0.035592 0.035602 0.011750 1.000x 1.005x
values-consumer-1k 0.001549 0.001556 0.004417 0.996x 1.000x
vector-update-2k 0.059372 0.062012 0.016250 0.957x 1.004x

Build: vile-resume.k_7mt74r. Final verification: vile-resume.8rrdw3_g. Preparation/measurement: vile-resume.754ci7js. Recovery: validation/interpreter-entry391/. All raw samples, scaling, first-call/process observations, caches, frozen inputs, source/compiler/binary hashes and logs remain available.