JS WAM: opt-in interpreter profiling (UW_PROFILE) - #4207
Open
s243a wants to merge 4 commits into
Open
Conversation
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
marked this pull request as ready for review
August 31, 2026 19:58
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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; noINTEGRATION_PATCH.md.Activation
Runtime._prof === null). When off,Runtime.run/collect_runuse the same instruction loop as before this change. Remaining cost isif (Runtime._prof)in unify / bind_var / new_var / Call-Execute-Proceed (~0% vs parent on fib(20) wall time; noise).UW_PROFILE=1(alsotrue/yes) → compact table on stderrUW_PROFILE=json→ one JSON object on stderrRuntime.profile(true|"json"|false)andRuntime.profileReport()for programmatic useMetrics
Per-predicate (exclusive):
calls,instr,ns,cps,max_cp_depth,loweredGlobal:
instructions,unify_calls,trail_pushes,heap_cells,backtracks,trail_undos,wall_nsLowered 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.plincluding (a) table + byte-identical stdout, (b) JSON parse withfib/2count ≥ 1, (c) default silent stderr, plus loweredhello/1call countstests/test_wam_javascript_lowered.pltests/test_wam_javascript_fact_sources.plfib(20) sample (
UW_PROFILE=1stderr; stdout byte-identical to unprofiled)(
A2 = +(4181, 2584)is a pre-existing naive-fib register/is-2 display quirk, not introduced here.)