Skip to content

perf(sv-analyzer): avoid cloning scalar call contexts - #1182

Merged
tignear merged 1 commit into
masterfrom
perf/sv-constant-call-contexts
Oct 10, 2026
Merged

tignear merged 1 commit into
masterfrom
perf/sv-constant-call-contexts

Conversation

@tignear

@tignear tignear commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Lowering a constant-function initializer such as f(P + 1) constructed PackedDimensions by copying every visible numeric binding and type alias, even though those operand-lowering branches do not read declaration metadata. Repeating this across a growing parameter prefix adds quadratic copying.

Classify the call operands first. Literals, bare identifiers, unary/binary expressions, parentheses, and nested user calls with those operands use an empty context. Selections, casts, system calls, patterns, conditional expressions, named arguments, and omitted arguments keep the original complete context. Expression lowering and later typed parameter evaluation remain the same.

Based directly on current master (281f7bd9c), independently of #1175. The standalone constant-function probe mode is compatible with the one in that PR.

Validation:

  • cargo fmt --all -- --check
  • cargo clippy --locked -p celox-sv-analyzer -p celox-frontend-sv --all-targets --all-features -- -D warnings
  • cargo test --locked -p celox-sv-analyzer -p celox-frontend-sv --all-features --quiet: 233 passed; two manual timing probes ignored by the normal suite.
  • cargo test --locked -p celox --features sv-dpi --test systemverilog --test sv_unpacked_array --test sv_dpi --test sv_packages --test interface --test advanced_interface --quiet: SystemVerilog 1,685, DPI 52, arrays 7, packages 45, interfaces 216 passed; 39 existing interface exclusions.
  • cargo test --locked -p celox-test-suite --features verilator,icarus --quiet: 56 tests plus two doctests passed; nine existing external-oracle tests remain ignored. Executable shared cases and adapters are unchanged, so external evidence is reused under CONTRIBUTING.md.
  • cargo doc --locked -p celox-sv-analyzer -p celox-frontend-sv --no-deps and pnpm docs:build passed.

The internal comparison exercises 21 argument forms against the former full-context lowering with 4,096 unrelated bindings, including signed parameters, symbolic/typedef casts, selects, size queries, zero divisions, nested calls, and unsupported forms. A 16/64/256-parameter source-to-IR arithmetic chain checks every value and zero context copies. The large debug regression uses an 8 MiB thread stack for existing recursive parameter substitution.

The optimized paired probe (compare_lazy_and_copied_scalar_call_contexts -- --ignored --nocapture) passed. With 512 unrelated parameters and 512 scalar call conversions, the seven-run median was 23.827 ms for full contexts versus 1.473 ms for classified contexts. It checks converted calls and excludes source parsing and function-body execution.

The standalone type_queries --constant-functions 32 128 512 probe passed with IR value assertions. At 512 parameters, separate three-sample medians comparing master with this change were 2,699.106 → 1,720.513 ms for AST lowering (parse 49.174 → 53.607 ms). The 32-parameter AST sample became slower (19.841 → 22.680 ms). Full results and commands are in the performance document; shared-machine timing varies and whole AST lowering remains nonlinear.

A diagnostic run with #1175 applied counted 18N function executions at N=16/64/256: the function-call count itself was linear. The performance notes distinguish that count from growing costs inside each call, repeated collection passes, and unresolved expression expansion. This change removes one environment-copying path; other contexts, declaration discovery, and unresolved expression expansion remain.

@tignear
tignear marked this pull request as ready for review October 10, 2026 19:02
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T19:04:26.566368Z 1fa33c1 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@tignear
tignear enabled auto-merge October 10, 2026 19:30
@tignear
tignear added this pull request to the merge queue Oct 10, 2026
Merged via the queue into master with commit 65dff8a Oct 10, 2026
25 checks passed
@tignear
tignear deleted the perf/sv-constant-call-contexts branch October 10, 2026 20:20
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