Repository navigation
perf(native): deduplicate compile tasks by unit classes instead of deep comparison - #1995
Merged
Merged
Conversation
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. |
…ep comparison The native backend found an existing task for each trigger by comparing its unit list with every task so far, unit by unit and block by block. An unfused comb-apply task starts with all of `eval_comb`, so each comparison walked the whole combinational program: O(triggers^2 x program size). On C906 the backend sat in compile_program for 19+ minutes, mostly in memcmp and HashMap<BlockId, BasicBlock>::eq. Each distinct execution unit is now hashed once and assigned a class of structurally equal units, and tasks are looked up by their list of classes. Two unit lists have the same classes exactly when they compare equal, and tasks are visited in the same order, so the tasks, their order and their bindings are the same as before and the generated code does not change. Closes #1982 Change-Id: I03837ef8fa9804562d781436411449be6cb1c9b8
tignear
force-pushed
the
feature/perf/1982-task-dedup
branch
from
October 25, 2026 12:13
b0c9ed9 to
f52c00e
Compare
Contributor
Merge Queue Status
This pull request spent 1 hour 47 minutes 43 seconds in the queue, including 1 hour 6 minutes 39 seconds running CI. Required conditions to merge
|
This was referenced Oct 25, 2026
Closed
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.
The native backend deduplicates compile tasks by looking, for each trigger, for an existing task whose unit list compares equal:
tasks.iter().position(|task| task.units == unit_refs).unit_refsis aVec<&ExecutionUnit>, so==compares units block by block. Every unfused comb-apply task starts with all ofeval_comb, so each comparison walks the whole combinational program, and the search costs O(triggers² × program size). On C906,compile_programran for 19+ minutes; a perf sample after 16 minutes still showed 55%memcmpand 35%HashMap<BlockId, BasicBlock>::eq.Change
NativeUnitClassesassigns each distinct execution unit a class of structurally equal units:Tasks are looked up in a map keyed by their list of classes:
(first_ff_unit, classes).Two unit lists get equal class lists exactly when they compare equal. Triggers are visited in the same order, and a lookup returns the task the linear search found first. So the tasks, their order and their bindings are unchanged, and so is the generated code. The cost is now proportional to the program size plus the total length of the unit lists.
Tests
backend::native::backend::tests::unit_classes_match_deep_comparison: over a pool of units that includes clones, repeated references and maps filled in a different order, every pair of unit lists of up to two units gets equal class lists exactly when the lists compare equal.native_mirsnapshots, which list each native function's bindings, are unchanged.celox/systemverilog,celox-test-suite/{verilator,icarus,xezim,runtime-cases}) overcelox,celox-frontend-svandcelox-test-suite: 14725 passed, 330 skipped (after rebasing on master 041f4d9).Like the other complexity-order fixes, this PR has no before/after benchmark.
backend/lanes.rs(the parallel lane-kernel planner) uses the same linearkernel.units == unitssearch. It is not changed here.Closes #1982