Skip to content

perf(bus): decide flat guest accesses inline when no foreign address space is attached - #1420

Merged
benletchford merged 1 commit into
benletchford:masterfrom
rlanday:perf/bus-route-flat-fast-path
Sep 5, 2026
Merged

perf(bus): decide flat guest accesses inline when no foreign address space is attached#1420
benletchford merged 1 commit into
benletchford:masterfrom
rlanday:perf/bus-route-flat-fast-path

Conversation

@rlanday

@rlanday rlanday commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Summary

MacMemoryBus::route runs on every bus read and write. Since #1364 it has been an out-of-line call that recomputes the address translation and consults the foreign address space before reaching the flat-RAM answer that the 68k-only configuration always takes; it carried #[inline] but LLVM declined it. This keeps the same decision order but splits the function: a small inline wrapper answers the common case from the translated address and the RAM size, and only an attached foreign space pays the out-of-line router.

Why

Part of the host-work regression found while re-baselining against master (see #1364 comment): route was 6.5% of self time on a 3 in Three replay.

Measurements

Measured together with the themed-chrome cache PR (the two were built as one step), paired hardware counters on the headless replay against a tree carrying rebased #1220 and the trap-table fix, identical ticks and framebuffer hash on every pair:

workload instructions / CPU time
3 in Three, 200 M −17.8% (5/5) / per-step CPU time to follow in a comment
SimCity 2000, 400 M −14.6% (5/5) / to follow

All four regression fixes together vs rebased #1220: −60.7% instructions, −53.0% CPU time (35.4 s → 16.6 s), 5/5 on 3 in Three, −39.1% instructions, −30.8% CPU time (18.6 s → 12.9 s), 5/5 on SimCity 2000.

Measured on builds based on c40588f, the master of the day; the branch is rebased onto d30234c, whose seven commits do not touch these paths.

The per-step instruction counts above were measured while the machine was loaded (cycles and CPU time were noise); the combined row was re-measured with the machine idle, and per-step CPU times from the same idle rerun follow in a comment.

Related fixes for the same regression: #1419 (trap-table lookup), #1420 (routing fast path), #1421 (themed chrome cache); #1220 removes the single-step mode they were measured on top of.

Tests

cargo test; see the trap-table PR for the one pre-existing failure.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UqCuD9vsGeeij5DdYt3vcK

…space is attached

MacMemoryBus::route runs on every bus read and write. Since the unified
runtime it was an out-of-line call that recomputed the address translation
and consulted the foreign address space before reaching the flat-RAM answer
that the 68k-only configuration always takes. Keep the same decision order
but answer the common case inline from the translated address and RAM size;
only an attached foreign space pays the router.
@rlanday

rlanday commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Per-step CPU time, re-measured with the machine idle (3 in Three headless replay, 200 M guest instructions, 3 pairs each, identical ticks and framebuffer hash on every pair; each step against the previous one in the order the fixes were built):

step host instructions CPU time
fix 1: no per-dispatch clone (#1419, first commit) −3.9% (3/3) +9.4% (0/3; cycles +11%)
routing fast path + dialog-frame cache (#1420 + #1421 first commit) −17.8% (3/3) −36.4% (3/3, 33.0 s → 21.1 s)
sorted, merged ranges (#1419, second commit) −47.7% (3/3) −33.8% (3/3, 20.4 s → 13.6 s)
menu bar + titles cache (#1421, second commit) −4.9% (3/3) −1.7% (2/3)

All four together vs rebased #1220 (5 pairs, both workloads): 3 in Three −60.7% instructions / −53.0% CPU time; SimCity 2000 −39.1% / −30.8%.

Note on the first row: removing the per-dispatch clone alone lowers the instruction count but costs CPU time (the borrowed check still walks the whole range list, now without the copy that had just pulled it into cache). The sorted-ranges commit removes that walk, so #1419 is measured as the pair; a run of #1419's two commits on their own is queued and will be posted here.

@benletchford benletchford left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

The early route uses the translated address returned by the existing contiguous-range check, preserving 24-bit wrap and mixed/foreign-memory handling. Tested together with #1419 and #1220 on current master: 4,987 library tests passed, three ignored; CI is green.

@benletchford
benletchford merged commit 7cf6212 into benletchford:master Sep 5, 2026
4 checks passed
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.

2 participants