Runner heap stats and playground run figures measure the script
Date: 2026-12-03
Area: apps, website, wasm
Related: ADR 0236, ADR 0247, JSON Output
Context
The website playground, sandbox demo, and landing-page console append a tail line to each run's output:
— exit 0 · 22.20ms · 663.9 KB GC peak · 84.70 MB heap allocated
Two of those three figures reflected engine startup rather than the script:
- Heap allocated (
memory.heap.deltaAllocatedBytes) —GocciaRunner,GocciaTestRunner, andGocciaBenchmarkRunnersampledHeapStart := GetHeapStatusbeforeTGocciaEngine.Create, while samplingMemoryStart := Engine.MemoryafterTGocciaEngine.Create. For single-file and per-file reports,memory.heap.deltaAllocatedBytestherefore included the engine's fixed startup reservations (VStack,Frames,Nursery, and built-ins: ~24 MiB natively, 84.7 MiB on 0.19.0 WebAssembly, and ~36 MiB after on-demand WebAssembly reservations). Even after sampling post-Create, FreePascal's heap counter depends on the target's nursery size (a 5 MB script stays inside an 8 MiB native nursery with ~20 KB of FPC heap growth while overflowing a 1 MiB WebAssembly nursery into old-space pages), and older vendored releases on the website still emit the pre-Createnumbers. - Run time (
timing.total_ns) — The tail line displayedtiming.total_ms(total_ns), which is end-to-end time from beforeTGocciaEngine.Create(~90–95% engine boot for short scripts). InGocciaTestRunner,timing.exec_nsalso subtracted a pre-Createtimestamp rather than measuring script and test-suite execution.
Decision
- Per-file
memory.heapstarts afterTGocciaEngine.Create.GocciaRunner,GocciaTestRunner, andGocciaBenchmarkRunnersampleHeapStart := GetHeapStatusimmediately afterEngine := TGocciaEngine.Create, matching the span ofMemoryStart := Engine.Memory. Multi-file aggregatememory.heapremains process-wide across the run (sampled beforeRunFilesand after all engines are freed). GocciaTestRunnerseparatesexec_nsfromtotal_ns.timing.exec_nsmeasures top-level file execution plus test-suite execution (RunResult.ExecuteNanoseconds + Res.DurationNanoseconds), excluding engine startup, whiletiming.total_nsremains end-to-end from before engine creation, matchingGocciaRunner.- The website's tail line reports script phase time and GC allocations.
- Duration uses
scriptDurationMs(timing): the sum of available phase timings (lex_ms + parse_ms + compile_ms + exec_ms), falling back tototal_msonly when phase timings are absent.timing.total_nsstays end-to-end in the JSON protocol and server telemetry. - Memory renders
memory.gc.peakLiveBytes(GC peak) andmemory.gc.allocatedDuringRunBytes(GC allocated) instead of FreePascal'smemory.heap.deltaAllocatedBytes, and appends(M freed)to the GC collection count only whencollectedObjects > 0(since the current engine does not count individual objects and emits0). normalizeMemorycontinues to parsememory.heap.deltaAllocatedBytes, andnormalizeTimingcontinues to parse all*_ns/*_msfields, so older vendored engine releases remain readable and render script-level figures on both server and browser hosts.
- Duration uses
Consequences
- Single-file and per-file
memory.heap.deltaAllocatedBytesin--output=jsonnow reflects FreePascal heap growth afterTGocciaEngine.Createrather than engine startup reservations; consumers comparing against earlier versions should account for this baseline shift. GocciaTestRunner'stiming.exec_ns(andexecuteTimeNanoseconds) excludes engine startup whiletiming.total_ns(andtotalEngineNanoseconds) continues to report end-to-end time, socompile_ns + exec_ns <= total_nsmatchesGocciaRunner.- The playground, sandbox, and landing-page tail lines show what the script compiled, executed, and allocated in the JS GC heap consistently across native server runs, WebAssembly browser runs, and older vendored releases.