Skip to content

perf(sv-analyzer): avoid repeated four-state environment copies - #1170

Merged
tignear merged 3 commits into
masterfrom
perf/sv-literal-parameter-environments
Oct 10, 2026
Merged

tignear merged 3 commits into
masterfrom
perf/sv-literal-parameter-environments

Conversation

@tignear

@tignear tignear commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Four-state parameter chains copied the growing numeric environment during every literal resolution, and width lowering copied two maps whenever any prefix literal was nonnumeric. Borrow literal-resolution inputs when there is no stale self-value to remove. For pure range headers with the same immutable base, borrow the range context unless a nonnumeric prefix binding masks an inherited numeric value.

The inherited-shadow condition is initialized once and updated conservatively with a direct name lookup for each binding, avoiding repeated prefix scans. Stale self-values, inherited numeric shadows, different bases and assignment-containing headers retain their previous copied/masked projections. Declared widths, signing, X/Z masks, overrides and diagnostics remain unchanged.

Owning-crate tests verify zero width/literal environment copies through complete AST and IR construction for 16/64/256 module and reverse generate chains. They check parameter masks, signal names/widths and generated assignments. Borrowed/copied comparisons cover inherited shadows, constructor/appended prefix parity, 4,096 unrelated bindings, stale self-values, wide literals, signed shifts, two-state conversion and unresolved names. No shared executable cases or external adapters are changed.

Performance

New type_queries --four-state-parameters mode: forward module chains and reverse generate chains starting with 'x, with final generated $bits(P0) and assignment assertions. Medians of three fresh parse/AST/IR runs in optimized heliodor-dev, excluding backend compilation and simulation. Before is the synchronized tree 7e4f3f1bc; after is the additional patch.

Four-state parameters Module AST before/after (ms) Generate AST before/after (ms)
32 25.513 / 71.532 1,033.913 / 493.074
128 140.524 / 219.675 6,596.133 / 2,495.723
512 1,807.363 / 633.479 10,672.026 / 9,170.822

After 16x input growth, AST time grows 8.9x for the module and 18.6x for the generated input. The large module sample is about 2.9x faster, while small module timings got worse with increased load. Parsing at 512 was 115.117/166.772 ms for the module and 146.045/214.184 ms for generate. Shared-machine variation is substantial; deterministic copy counters establish the removed work independently of timing ratios.

These original timing samples precede the later master system-function/query updates. Preliminary generated $bits discovery was still costly in the measured tree. This change does not claim a material overall generate speedup or linear scaling for every scope pattern. Phase timings, limitations and reproduction commands are in docs/internals/sv-analysis-performance.md.

Validation

Validated after synchronizing master 7565d94cb (including merged #1168), with Rust 1.99.0 in the locked Nix environment and default mbx-managed Cargo targets:

  • Formatting and 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 — 227 passed; doctests passed.
  • 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 — 1,617 SV, 52 DPI, 7 array, 37 package and 216 interface tests passed; 39 existing interface exclusions remain. Native/Cranelift/Wasm and applicable parallel/four-state variants are included.
  • cargo test --locked -p celox-test-suite --features verilator,icarus --quiet — 52 library/integration tests and 2 doctests passed; 9 existing external oracles ignored.
  • cargo doc --locked -p celox-sv-analyzer -p celox-frontend-sv --no-deps and pnpm docs:build.
  • Original four-state, numeric and ranged probes at 32/128/512; after synchronization, the four-state probe passes again at 16/64/256 with IR width/mask assertions. Docs rendering was unchanged by the merge; the previously successful pnpm docs:build result is retained.

Analyzer-only changes against unchanged shared cases do not require external reruns under AGENTS.md/CONTRIBUTING.md. Retained reports and proof manifests are unchanged. Public APIs/bindings are unchanged; default NAPI does not enable this frontend.

@tignear
tignear marked this pull request as ready for review October 10, 2026 10:57
@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-10T10:59:50.035296Z ac2465f 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 added this pull request to the merge queue Oct 10, 2026
Merged via the queue into master with commit ef37b2c Oct 10, 2026
26 checks passed
@tignear
tignear deleted the perf/sv-literal-parameter-environments branch October 10, 2026 11:56
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