Skip to content

JS WAM: opt-in interpreter profiling (UW_PROFILE) - #4207

Open
s243a wants to merge 4 commits into
grok/wamjs-string-literalfrom
grok/wamjs-profiling
Open

JS WAM: opt-in interpreter profiling (UW_PROFILE)#4207
s243a wants to merge 4 commits into
grok/wamjs-string-literalfrom
grok/wamjs-profiling

Conversation

@s243a

@s243a s243a commented Aug 31, 2026

Copy link
Copy Markdown
Owner

Opt-in JS WAM profiler so we can see where a program spends time before investing in indexing depth or parallelism.

Branched from grok/wamjs-string-literal (extends that stack; net additions only). No shared-file changes; no INTEGRATION_PATCH.md.

Activation

  • Off by default (Runtime._prof === null). When off, Runtime.run / collect_run use the same instruction loop as before this change. Remaining cost is if (Runtime._prof) in unify / bind_var / new_var / Call-Execute-Proceed (~0% vs parent on fib(20) wall time; noise).
  • UW_PROFILE=1 (also true/yes) → compact table on stderr
  • UW_PROFILE=json → one JSON object on stderr
  • Runtime.profile(true|"json"|false) and Runtime.profileReport() for programmatic use
  • Stdout is unchanged when profiling is on (conformance harness reads stdout)

Metrics

Per-predicate (exclusive): calls, instr, ns, cps, max_cp_depth, lowered
Global: instructions, unify_calls, trail_pushes, heap_cells, backtracks, trail_undos, wall_ns

Lowered tier: call counts only (dispatch wrapper). Interpreter-tier has instruction/CP/time detail.

JSON schema and table format are documented in docs/WAM_JAVASCRIPT_STATUS.md.

Tests (all green)

  • tests/test_wam_javascript_builtins.pl including (a) table + byte-identical stdout, (b) JSON parse with fib/2 count ≥ 1, (c) default silent stderr, plus lowered hello/1 call counts
  • tests/test_wam_javascript_lowered.pl
  • tests/test_wam_javascript_fact_sources.pl
  • Local 48-query stand-in in the builtins suite (official harness still has no javascript adapter)

fib(20) sample (UW_PROFILE=1 stderr; stdout byte-identical to unprofiled)

A1 = 6765
A2 = +(4181, 2584)
true

UW profile  (interpreter instr/CP/time; lowered = calls only)
pred                             calls       instr     CPs   maxCP            ns
fib/2                            21891      437805   21891   10946     242584060
--
instr=437805 unify=76617 trail=43781 heap=76616 backtracks=21890 undos=0 wall_ns=244314436

(A2 = +(4181, 2584) is a pre-existing naive-fib register/is-2 display quirk, not introduced here.)

Open in Web Open in Cursor 

cursoragent and others added 4 commits August 31, 2026 19:54
Instrument the interpreter behind a single Runtime._prof flag check so
the hot path stays allocation-free when profiling is off. UW_PROFILE=1
prints a compact per-predicate table to stderr; UW_PROFILE=json emits a
stable JSON object. Lowered dispatch records call counts only.

Co-authored-by: johns243a <johns243a@gmail.com>
Co-authored-by: johns243a <johns243a@gmail.com>
PLUnit assertion/1 uses double negation, so Calls/Row never leaked to
the subsequent numeric checks.

Co-authored-by: johns243a <johns243a@gmail.com>
Runtime.run/collect_run now branch once on Runtime._prof: the off path
is the previous instruction loop; instrumentation stays in
run_one_instruction. Also cut leftover choice points in the profile
table/JSON helpers.

Co-authored-by: johns243a <johns243a@gmail.com>
@s243a
s243a marked this pull request as ready for review August 31, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants