Repository navigation
perf(sv): analyze each scope in time proportional to its own size - #1957
Merged
mergify[bot] merged 1 commit intoOct 25, 2026
Merged
Conversation
Per-scope analysis selected arena entries by token range by scanning the whole source file's arenas, so a design shipped as one file cost (analyses x file size). A per-file span index now orders each arena by first token; a scope visits only the entries starting inside its own ranges, in arena order, and applies the same predicates. Facts that are pure functions of the file (constant-value nodes, callees, exclusion ranges, override dimensions, qualified bases, pattern keys and the timescale source key with its hash) are computed once per file. Diagnostics and lowering are unchanged. Closes #1956 Change-Id: I283e94ab1244d6aa8c08bfb4af44b1bca00a8e4d
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Contributor
|
Queued — the merge queue status continues in this comment ↓. |
Contributor
Merge Queue Status
This pull request spent 58 minutes 37 seconds in the queue, including 56 minutes 51 seconds running CI. Required conditions to merge
|
40 of 71 tasks
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.
What
The SV analyzer's per-scope checks visited every entry of every arena in the source file for each scope they validated, and kept only the entries inside the scope's token ranges. A design shipped as one file therefore cost roughly (number of scope analyses × file size). For rtlmeter's C906 (
c906_all.v: 150k lines, 289 modules), that came to most of the 11 minutes reported in #1956.Each scope now costs what its own token ranges contain:
source_tree::spansbuilds a per-file index once, on first use: the arenas (expressions, types, body items, nets, instantiations, subroutines) ordered by first token.Starts::within(ranges)returns the entries that start inside a scope's ranges, in arena order. Callers apply the same predicate as before. Every entry a range contains starts inside it, so the selected set and the visit order (which decides the first diagnostic) are unchanged.Rangesanswers the "is this range or token inside any of these ranges" checks in O(log n), replacing linearanyscans. The index lives next to the sharedDeclarationsand is dropped whenever they are mutated throughDerefMut.validation::Facts: the constant-value node closure (theskipped::childrenwalk), callees, generate controls, parameter defaults, procedural ranges, cast exclusions, type-argument override dimensions, header ports and packed dimensions.imports::Facts: qualified-name bases and pattern keys.needs_selectedfor parameter defaults.validate_scope/reject_constant_calls,timescales::validate_queries,generate::parameter_literal_references,ScopeImports::from_scope,imports::unqualified_names(also quadratic within a scope throughqualified.iter().any),type_binding::packed_rangesand the function warnings.Measurements
The C906 numbers come from a local stack that is never pushed: master + #1893, #1952, #1954 and #1950. On master the design is rejected before analysis (hierarchical references, non-ANSI ports). The binaries use the
heliodor-devprofile, run undercelox run --top tb --two-state --unlimited survey.v(c906_all.vwith the local edits from the issue), pinned totaskset -c 8-11.$readmemhstop (run outside the testbench directory)hello/, through to the #1955 false loop (same stop as the issue)¹ This baseline run shared the machine with a build part of the time, so it overstates the baseline somewhat. The analyzer-only row above is the clean comparison.
The diagnostics are byte-identical before and after in both workloads. In the full run, about 60% of what remains is
celox_frontend_core::watch::instrument_unit, which the issue leaves for a separate look. The SV analyzer is now about 5%.Small designs are not slower (
perf stat -r 20/30, task-clock, masterde79c93c6fvs this branch):verification/repros/integer_edges.svbenches/verilator/Fifo.svb2_vm_dispatch_bit_short.sv(native)Generated code is unchanged. On
b2_vm_dispatch_bit, native backend, callgrind scoped toSimulationState::step_until:Validation
cargo nextest run --workspace --exclude 'lydite*' --profile ci --features celox/systemverilog,celox-test-suite/verilator,celox-test-suite/icarus,celox-test-suite/xezim,celox-test-suite/runtime-cases: 17257 passed, 340 skipped.source_tree::spanscomparewithin,containing,covering,containsandcoverswith brute-force scans over every range of a short token sequence.c4229f3bd522,--state-mode both --expected conformance/sv-tests/expected.tsv): matches the expectations.cargo fmt --check;cargo clippy -p celox-sv-analyzer -p celox-frontend-sv --all-targets: clean.Closes #1956