Skip to content

perf(sv-analyzer): borrow constant function environments - #1175

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

tignear merged 1 commit into
masterfrom
perf/sv-constant-function-environments

Conversation

@tignear

@tignear tignear commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Constant-function evaluation cloned all visible values and scanned their type markers on every call. The literal evaluator also executed unsupported user functions with an empty environment before falling back to numeric evaluation, multiplying repeated work in recursive expressions.

Borrow the caller's values, keep writes in a local frame, and query width/signedness markers only for referenced names. Nested calls borrow the previous frame. Reject unsupported literal function evaluation before executing it, so a 12-level recursion now executes 13 calls and exceeding the depth limit executes 64 calls. Public map-based evaluator APIs stay unchanged.

This draft builds on #1174. It includes the current master (ef37b2c6c); only the new branch was pushed.

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: 235 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,617; DPI 52; arrays 7; packages 37; interfaces 216 passed, with 39 existing interface exclusions.
  • cargo test --locked -p celox-test-suite --features verilator,icarus --quiet: 52 tests plus two doctests passed; nine existing external-oracle tests remain ignored. Shared executable cases and adapters are unchanged, so external results are reused under CONTRIBUTING.md.
  • cargo doc --locked -p celox-sv-analyzer -p celox-frontend-sv --no-deps and pnpm docs:build passed.

Internal regressions compare results with the former copied initialization, check caller isolation, local/argument/return-variable shadowing, signed shifts, symbolic argument widths, selected writes, unresolved values, nested calls, and depth restoration. A counted environment performs the same lookups with 16, 256, and 4,096 unrelated bindings.

The manual optimized paired probe (compare_borrowed_and_copied_function_environments -- --ignored --nocapture) passed. For 512 unrelated parameters and 512 leaf calls, the median was 53.946 ms with copied initialization versus 0.305 ms with borrowing. This isolates frame initialization/evaluation and checks every result; it excludes parsing, declaration discovery, and backend compilation.

The new type_queries --constant-functions 32 128 512 mode passed with IR value assertions. At 512 parameters, separate three-sample medians comparing 21eb07cf3 with this change were 2,652.147 → 1,170.084 ms for AST lowering (parse 56.719 → 51.676 ms). Full measurements and reproduction commands are in the performance document. Shared-machine timing varies, and overall AST lowering remains nonlinear because other collectors repeatedly resolve parameter prefixes. The baseline also overflows a default Rust test thread stack for the 256-element function-call chain; that owning-crate regression uses an 8 MiB stack. Recursive parameter substitution's existing stack use remains.

@tignear
tignear marked this pull request as ready for review October 10, 2026 13:24
@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-10T13:26:57.336933Z 6332d3d 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.

Base automatically changed from perf/sv-parameter-value-resolution to master October 10, 2026 14:38
@tignear
tignear added this pull request to the merge queue Oct 10, 2026
Merged via the queue into master with commit a6a74c7 Oct 10, 2026
18 checks passed
@tignear
tignear deleted the perf/sv-constant-function-environments branch October 10, 2026 20:16
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