Skip to content

WIP: perf(executor): allocation-free trap-liveness probes (Refs #349) - #2372

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/349-interp-perf-master
Oct 31, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/349-interp-perf-master

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

WIP: perf(executor): allocation-free trap-liveness probes (Refs #349)

What

Every per-command / per-pipeline-stage / per-function-call site that asked
"is trap X live?" through builtins::trap::get_trap_action paid for a
TRAP_RESET BTreeSet build plus an action String clone (and a formatted key
String) just to compute a boolean. Those sites now use the pre-existing
allocation-free forms from the #1121/#375/#186 work:

  • active_trap_action_ref (borrowing, stack-buffer key, split-scan reset
    test; Some iff action present, non-empty, not reset) for the pure
    presence verdicts: ast_exec ERR sample, comsub errtrace / functrace-DEBUG
    gates, compound_exec EXIT gate, job_builtins signal-death checks, all
    pipeline_exec DEBUG-trap bail-outs, embedded_mutations DEBUG gate.
  • get_trap_action_fast (identical Option<String>, split-scan reset test,
    no BTreeSet) for the function_calls RETURN-trap save, which needs the
    action value itself.

Semantics unchanged: reset-list signals read as unset, empty actions read as
unset — identical to get_trap_action. Sites whose contract is
presence-including-empty (external_inner EXIT/ERR spawn gate, limit_builtins
ignore check) or that consume the action value (trap_exec firing machinery,
job_builtins interrupt scan) deliberately keep get_trap_action.

This is a mechanism-level change (how trap liveness is queried across the
whole executor), not a per-shape optimization.

Provenance

Ported from the d758fd0-based evidence branch fix/349-interp-perf
(commit 0a3383f) by clean cherry-pick: zero conflicts, diffstat and changed
lines identical (7 files, +37/−27). Bench evidence below was gathered on
that twin tree with the identical patch.

Bench (Linux, this 2-core VM, "fast" release profile: opt3, no LTO, 16 CGU)

Interleaved A/B (bench_ab.py, 9 samples, medians, rusage CPU primary;
every shape's stdout sha-verified identical between binaries, "out OK"):

shape cpu Δ wall Δ
pipe_probe (DEBUG trap per stmt) −4.7% −61.5%
s1_349_arith_assign −4.8…−6.7% noisy under load
func_colon_20k −6.3…−11.2% −6.9…−43.5%
func_args_20k −8.3…−11.2% −28.1% (one run)
while_colon_20k −9.3% −16.6%
loop/assign shapes −0.4…−6.6% noisy under load

Wall figures swing with the heavily loaded shared VM (load avg 4–16 during
runs); rusage CPU is the stable figure and improves on every shape. Two
independent runs agree on CPU direction and magnitude.

Verification

  • Local: cargo check --locked clean on this tree; rustfmt clean on all
    touched files; lib + regression suite verdict in the cluster REPORT
    (collector re-run on this tree; CI also runs its standard gates).
  • No src/lexer/continuation.rs changes.

Refs #349 (PERF-BASELINE interpreter-perf item). Draft — do not merge.

…obes (Refs #349)

Every per-command / per-pipeline-stage / per-function-call site that
asked "is trap X live?" through builtins::trap::get_trap_action paid
for a TRAP_RESET BTreeSet build plus an action String clone (and a
formatted key String) just to compute a boolean. Those sites now use
the pre-existing allocation-free forms from the #1121/#375/#186 work:

- active_trap_action_ref (borrowing, stack-buffer key, split-scan
  reset test; Some iff action present, non-empty, not reset) for the
  pure presence verdicts: ast_exec ERR sample, comsub errtrace /
  functrace-DEBUG gates, compound_exec EXIT gate, job_builtins
  signal-death checks, all pipeline_exec DEBUG-trap bail-outs,
  embedded_mutations DEBUG gate.
- get_trap_action_fast (identical Option<String>, split-scan reset
  test, no BTreeSet) for the function_calls RETURN-trap save, which
  needs the action value itself.

Semantics unchanged: reset-list signals read as unset, empty actions
read as unset — identical to get_trap_action. Sites whose contract is
presence-including-empty (external_inner EXIT/ERR spawn gate,
limit_builtins ignore check) or that consume the action value
(trap_exec firing machinery, job_builtins interrupt scan) deliberately
keep get_trap_action.

Ported from the d758fd0-based evidence branch fix/349-interp-perf
(commit 0a3383f) by clean cherry-pick (zero conflicts, identical
diffstat); all bench/probe/test evidence in the PR description was
gathered on that twin tree.
@caomengxuan666

Copy link
Copy Markdown
Member Author

Collector verification on this tree (Linux, this VM):

Full record: cluster REPORT.md (fix-349-interp-perf workdir). Draft stays draft.

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.

1 participant