Skip to content

perf(native): deduplicate compile tasks by unit classes instead of deep comparison - #1995

Merged
mergify[bot] merged 1 commit into
masterfrom
feature/perf/1982-task-dedup
Oct 25, 2026
Merged

mergify[bot] merged 1 commit into
masterfrom
feature/perf/1982-task-dedup

Conversation

@tignear

@tignear tignear commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

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_refs is a Vec<&ExecutionUnit>, so == compares units block by block. Every unfused comb-apply task starts with all of eval_comb, so each comparison walks the whole combinational program, and the search costs O(triggers² × program size). On C906, compile_program ran for 19+ minutes; a perf sample after 16 minutes still showed 55% memcmp and 35% HashMap<BlockId, BasicBlock>::eq.

Change

NativeUnitClasses assigns each distinct execution unit a class of structurally equal units:

  • A unit is hashed once, independent of its maps' iteration order.
  • It is then compared only against the representatives in its hash bucket.
  • A unit reference seen before resolves by pointer.

Tasks are looked up in a map keyed by their list of classes:

  • Edge tasks: one map shared by the three edge labels, as the old search spanned them.
  • Comb-apply tasks: keyed by (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

  • New 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.
  • The existing native_mir snapshots, which list each native function's bindings, are unchanged.
  • Affected tests with CI features (celox/systemverilog,celox-test-suite/{verilator,icarus,xezim,runtime-cases}) over celox, celox-frontend-sv and celox-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 linear kernel.units == units search. It is not changed here.

Closes #1982

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 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-25T12:14:28.394916Z f52c00e New commits
ℹ️ 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 the merge-ready Request merging through Mergify after required checks label Oct 25, 2026
…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
tignear force-pushed the feature/perf/1982-task-dedup branch from b0c9ed9 to f52c00e Compare October 25, 2026 12:13
@mergify mergify Bot added the queued Mergify queue entry label Oct 25, 2026
@mergify

mergify Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
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
  • check-success = Conventional Commit title
  • check-success = Queue validation
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Lint & Format
    • check-neutral = @github-actions/Lint & Format
    • check-skipped = @github-actions/Lint & Format
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-neutral = @github-actions/NAPI Build (Linux ARM64 GNU)
    • check-skipped = @github-actions/NAPI Build (Linux ARM64 GNU)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/NAPI Build (Windows)
    • check-neutral = @github-actions/NAPI Build (Windows)
    • check-skipped = @github-actions/NAPI Build (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Rust Test & NAPI Build
    • check-neutral = @github-actions/Rust Test & NAPI Build
    • check-skipped = @github-actions/Rust Test & NAPI Build
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Ubuntu)
    • check-neutral = @github-actions/JS Test (Ubuntu)
    • check-skipped = @github-actions/JS Test (Ubuntu)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/JS Test (Windows)
    • check-neutral = @github-actions/JS Test (Windows)
    • check-skipped = @github-actions/JS Test (Windows)
  • any of [🛡 GitHub repository ruleset rule master]:
    • check-success = @github-actions/Conventional Commit title
    • check-neutral = @github-actions/Conventional Commit title
    • check-skipped = @github-actions/Conventional Commit title

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-ready Request merging through Mergify after required checks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(native): task deduplication compares whole execution units for every trigger

1 participant