Skip to content

perf(runtime): defer settles in compiled slots until their results are read - #1923

Merged
mergify[bot] merged 2 commits into
masterfrom
feature/lazy-settle
Oct 24, 2026
Merged

mergify[bot] merged 2 commits into
masterfrom
feature/lazy-settle

Conversation

@tignear

@tignear tignear commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1123, step 3b-2: the lazy settle from the compiled-slot frequency analysis (before #1786 D).

In the time slots the compiled scheduler runs, the settle after a domain's commit ran in every slot that fired a domain, though usually nothing in the run reads its results: only the host does, after the run. Such a settle now stays pending until something observes it, and runs where the reference loop ran it last, so every observer sees the reference's values. On the scheduler overhead benches a cycle drops by 19–24% in Ir (ac 690 → 525, b1 900 → 724, d 728 → 564), and by 32% on a variant whose registers read always_comb next-state logic.

What changes

The settle stays pending (the scheduler's dirty flag stays set) and runs:

  • for the host: before the run returns at its limit, or after a clock overflow (which ends a complete slot);
  • for a kernel that loads storage combinational logic writes, or may end the run in the middle of a slot ($finish, which is its status, or an error): before the slot it is due in. A waiting kernel that observes it may wake in any pass, so it runs before every slot and every further pass. Once a constant delay of a kernel may overflow, before every slot, as the run then returns in the middle of it;
  • for a domain that may end the run, or reads combinational outputs without fused units: before it evaluates. Slots that fire several domains whose units observe it: before their units;
  • a domain that reads combinational outputs and has fused units (Veryl frontend) runs them instead: they compute what it reads, then evaluate and apply, and the settle stays pending.

Combinational logic with effects of its own (records, captures, external calls, trigger marks), that may fail, or that keeps state between settles keeps every settle where the reference has it, as before. Keeping state is structural: a load of storage combinational logic writes that stores earlier in the same settle do not cover on every path (a forward must-store analysis over the comb units in settle order). That covers latches, the guarded units of always @* and other processes lower_comb_process lowers (they compare against snapshots of their inputs), and feedback. It is per design, since an eager latch may read the outputs of the rest. The waits the scheduler checks never watch combinational outputs (they already fall back), which a debug assertion now states.

All settles of the unit share one copy of combinational logic, entered with a continuation per call site, as the two settles did before.

Limitation: the SystemVerilog frontend builds no fused units, so an SV domain whose flip-flops read always_comb outputs settles before it evaluates: the same number of settles as before. Fused units for SV would let it skip them.

Validation

  • differential tests (lib): new deferred_settles_reach_their_readers (a domain whose next state is always_comb, a delay kernel sampling a combinational output, a waiting kernel sampling it in the pass after the clock kernel changed it, host writes between runs; native and Cranelift), fused_domains_compute_what_they_read (Veryl, fused units), compiled_slots_fail_in_a_domain_as_the_reference ($fatal), stateful_combinational_logic_settles_every_activation (an always_latch opened and closed between observers, a latch on a register-toggled gate, its always @* variant and a pure always @*); combinational outputs added to the kernel-$finish, delay-overflow and clock-overflow tests, whose state files must equal the reference's.
  • Mutation-checked: dropping each rule (limit settle, clock-overflow settle, delay-kernel observers, waiting-kernel observers at slot start and after a pass, domains that end the run, fused units, several domains, the overflow bound, kernel $finish, state-keeping combinational logic) fails at least one of these tests.
  • cargo test -p celox --features systemverilog --test systemverilog --test sv_update_events in the compiled, differential and differential-runs scheduler modes: 4,537 + 36 passed each; --lib 218 passed; the timed-runtime integration tests (checkpoint, state_file, vcd, sv_vcd, simulation_step/stop/limits, time_state_and_delays, processes, tiered, tick_semantics, edge_api, …): all passed.
  • node scripts/run-vtest.mjs --test systemverilog -E 'test(timing::)' with CELOX_SCHEDULER=differential and compiled: 656 passed each (a bogus CELOX_SCHEDULER value fails every case, so the mode reaches the executor).
  • clippy -D warnings (celox, celox-runtime, celox-napi; tests, examples), the default-feature lib test build without warnings, cargo fmt --check: clean. wasm32 NAPI build: builds.

Perf

examples/sched_bench, callgrind, Ir per cycle = (Ir at 200,000 cycles − Ir at 20,000) / 180,000, median of 3, release, native backend, same session:

bench master this PR change
ac (64 registers, host clock, no kernels) 690.1 525.4 −23.9%
b1 (clock kernel, waiting stimulus kernel) 899.7 724.0 −19.5%
b5 (as b1, nonblocking stimulus) 913.0 742.0 −18.7%
bh (host clock, waiting stimulus kernel) 851.0 687.0 −19.3%
d (clock kernel only) 728.0 563.5 −22.6%
bn (as b1, registers read always_comb next state; local variant, not committed) 1,406.0 949.0 −32.5%
  • The benches' combinational logic is the 64-term sum out, which only the host reads: it now settles once per run instead of once per cycle.
  • bn's domain reads combinational outputs and the SV frontend has no fused units, so it settles before the domain: once per cycle instead of twice (its comb also reads the stimulus, so master settled both before and after the domain).
  • Build cost: the total Ir at 20,000 cycles is lower than master's on every bench (e.g. b1 482.1M vs 490.2M), so compilation did not grow.

…e read

The compiled scheduler settled combinational logic after every pass of
the process phase and after the NBA region, as the reference loop does.
Since #1811 it skips a settle whose inputs did not change, but the settle
after a domain's commit ran in every slot that fired one, though usually
only the host reads its results, at the end of the run.

Such a settle now stays pending (the dirty flag stays set) until
something observes it, and runs at the point the reference ran it last,
so every observer sees the reference's values:

- the host: before the run returns at its limit or after a clock
  overflow, which ends a complete slot;
- a kernel that loads storage combinational logic writes, or may end
  the run in the middle of a slot ($finish, an error): before the slot
  it is due in, or, for a waiting kernel, which may wake in any pass,
  before every slot and pass; every kernel once a constant delay may
  overflow, as the run then returns in the middle of the slot;
- a domain that may end the run, or reads combinational outputs without
  fused units: before it evaluates; slots that fire several domains whose
  units observe it: before their units;
- a domain that reads combinational outputs and has fused units (Veryl):
  the fused units compute what it reads, then evaluate and apply.

Combinational logic with effects of its own or that may fail keeps
every settle where the reference has it. The waits
the scheduler checks never watch combinational outputs, which a debug
assertion now states.

Change-Id: I5aa9c77efe9277bde745a55de530c352804f875e
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 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-24T19:45:32.589865Z e7428ed 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 72f732adf5

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/celox/src/scheduler.rs Resolved
…e does

A deferred settle merges the settles it replaces into one, which is only
equivalent when a settle is a function of its inputs. Combinational logic
that keeps state between settles is not: a latch keeps what it captured
while open, and the guarded units of `always @*` and similar processes
run on a change of their inputs since their last activation, so a latch
opened and closed between two observers, or inputs that changed and
changed back, gave other results than the reference's.

Combinational logic now settles lazily only when no settle reads what an
earlier one left: every load of storage it writes is covered, on every
path, by stores earlier in the same settle. Guarded units load their
snapshots first, and feedback reads the previous value, so designs with
either keep every settle where the reference has it, skipping only those
whose inputs did not change.

Change-Id: I568c6d92c6fa2c2b1a1fb64ffccfe1a3151aab5b
@mergify

mergify Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Queued — the merge queue status continues in this comment ↓.

@tignear tignear added the merge-ready Request merging through Mergify after required checks label Oct 24, 2026
@mergify mergify Bot added the queued Mergify queue entry label Oct 24, 2026
@mergify

mergify Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

This pull request spent 51 minutes 13 seconds in the queue, including 33 minutes 28 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

@mergify
mergify Bot merged commit 01c8259 into master Oct 24, 2026
23 checks passed
@mergify
mergify Bot deleted the feature/lazy-settle branch October 24, 2026 21:36
@mergify mergify Bot removed the queued Mergify queue entry label Oct 24, 2026
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.

1 participant