Browse documentation

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:

  1. Heap allocated (memory.heap.deltaAllocatedBytes) — GocciaRunner, GocciaTestRunner, and GocciaBenchmarkRunner sampled HeapStart := GetHeapStatus before TGocciaEngine.Create, while sampling MemoryStart := Engine.Memory after TGocciaEngine.Create. For single-file and per-file reports, memory.heap.deltaAllocatedBytes therefore 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-Create numbers.
  2. Run time (timing.total_ns) — The tail line displayed timing.total_ms (total_ns), which is end-to-end time from before TGocciaEngine.Create (~90–95% engine boot for short scripts). In GocciaTestRunner, timing.exec_ns also subtracted a pre-Create timestamp rather than measuring script and test-suite execution.

Decision

  • Per-file memory.heap starts after TGocciaEngine.Create. GocciaRunner, GocciaTestRunner, and GocciaBenchmarkRunner sample HeapStart := GetHeapStatus immediately after Engine := TGocciaEngine.Create, matching the span of MemoryStart := Engine.Memory. Multi-file aggregate memory.heap remains process-wide across the run (sampled before RunFiles and after all engines are freed).
  • GocciaTestRunner separates exec_ns from total_ns. timing.exec_ns measures top-level file execution plus test-suite execution (RunResult.ExecuteNanoseconds + Res.DurationNanoseconds), excluding engine startup, while timing.total_ns remains end-to-end from before engine creation, matching GocciaRunner.
  • 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 to total_ms only when phase timings are absent. timing.total_ns stays end-to-end in the JSON protocol and server telemetry.
    • Memory renders memory.gc.peakLiveBytes (GC peak) and memory.gc.allocatedDuringRunBytes (GC allocated) instead of FreePascal's memory.heap.deltaAllocatedBytes, and appends (M freed) to the GC collection count only when collectedObjects > 0 (since the current engine does not count individual objects and emits 0).
    • normalizeMemory continues to parse memory.heap.deltaAllocatedBytes, and normalizeTiming continues to parse all *_ns/*_ms fields, so older vendored engine releases remain readable and render script-level figures on both server and browser hosts.

Consequences

  • Single-file and per-file memory.heap.deltaAllocatedBytes in --output=json now reflects FreePascal heap growth after TGocciaEngine.Create rather than engine startup reservations; consumers comparing against earlier versions should account for this baseline shift.
  • GocciaTestRunner's timing.exec_ns (and executeTimeNanoseconds) excludes engine startup while timing.total_ns (and totalEngineNanoseconds) continues to report end-to-end time, so compile_ns + exec_ns <= total_ns matches GocciaRunner.
  • 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.