perf(menu): a tab shown again reads only the rows that moved; the settings generation covers every field #2874
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2874
Loading…
Reference in a new issue
No description provided.
Delete branch "HumanBean/Longshot:perf/menu-ui-render"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Switching to a tab of the Insert menu with many rows did all its reading at once. The first frame read the tab's declarations and laid them out. The next frame read every row's state and also drew the first rows. That second frame was the heaviest of the switch. With every system row in the menu (#2861: the Graphics tab has 58), it went over the menu's 4.5 ms budget in the debug cost test.
This change does three things:
laidOutalso builds the menu's own lines more cheaply: one shared flags object, and no set to follow an anchor's chain.Profiling (stack samples of
mod teston the release fake game) showed where a switch's time goes. Per frame, it is about 24 components drawn and their commit. The rest was the reads: about 0.2 ms to read the rows and 0.3 ms for the declarations and their layout, all landing on the switch's first drawing frame. With the reads moved, the heaviest frame is now an ordinary drawing frame.Files to read:
game/mods/menu/src/main.tsx(declsOf, thelaidread inMenu),game/crates/api/src/services/settings_host.rs(generation_of),game/mods/menu/test/menu.test.ts(the cost test and the new reads test).Testing
Tested: Linux, RTX 3090.
Queue jobs:
cargo test -p modtool the_typescript_system_mods_pass_their_tests(debug) passes, every menu test included.cargo test -p api settings_hostandcargo clippy -p apipass.dev.py packanddev.py rtpass.Smoke run, headless (shared queue): kokiri-start, then Insert, then all seven tabs stepped through. Status showed
menu_open, hosted bysystem/menu, and the log has no script error. One 3.7 ms warning for the menu's first open came while the PC was paging. The bridge's screenshots do not include the menu.New test: "a page switched to again reads no declarations until they change; its rows are read with them". It fails on #2861: the rows were read a frame after the declarations.
Cost test, made stricter: a tab shown again is held to
SWITCH_MS4.5 ms again, with every system row. A tab's first showing is timed apart, underFIRST_MS5.5 ms (the switch's ceiling in #2861). For it, the rows are declared again with a label changed, which gives a new generation, and the test asserts that the declarations were read again.Generation test:
a_row_declared_again_with_another_format_or_default_moves_the_generation_on(cargo test -p api): another unit, display scale or default each move the generation on (review L1).Revisit test, frame by frame: the Audio tab shown again has its rows read in a frame before the one that first draws it, and none in that frame (review L2).
Queue job on
656c1a57:cargo test -p modtool(228 passed),cargo test -p api --lib(452 passed), clippy-D warningsand rustfmt pass.Release fake game: all 34 menu tests pass on
mod test(release builder).Still to test:
Measurements
Verdict: in the debug test, a tab shown again now costs 1.61 ms in its heaviest frame, against 4.49 ms before. A tab's first showing is as before.
Setup: Linux, RTX 3090; the menu's cost test (
LONGSHOT_COST_REPORT=1), its heaviest frame of script CPU while a tab or page is switched to, the least of 5 samples (#2861: every switch read the declarations again; here, a tab shown again). Each side is the least of 5 samples in one job, the two sides from separate jobs, not interleaved.656c1a57after it changes only the generation's hash (once per declarations' list, not per frame) and the tests, so the numbers hold for the head.12f42db51dcf4b82cargo test -p modtool(the test's ceiling)Risks
Checklist
Ready for review
mod-api; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). On656c1a57: 836 passed, 1 failed:tests/test_lifter.py(the builder'scontrol::tests::the_socket_is_made_private_and_a_client_handed_over), code this PR does not touch; mod-api's own CI fails run_all at12f42db5.main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
tests/that reads changed source is updated, not weakened.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
https://claude.ai/code/session_016o1k1SQVyAWsujjFVd8Wuc
289c9c563d1dcf4b82bcRebased onto mod-api
12f42db5now that #2861 is merged: no longer stacked, no conflicts; menu tests pass (Graphics shown again 1.74 ms debug).@review
Recommendation: Request changes. Cached declarations can retain an old slider format or default after a mod redeclares a setting.
The change keeps laid-out menu pages and reads their rows one frame earlier when revisiting them. That can spread switch work across frames, at the cost of retaining page layouts and relying on complete cache invalidation.
Blocking (2): must change before merging.
game/crates/api/src/services/settings_host.rs:200: The generation omits the declaration's format and default, although the cached declaration contains both. (more on the line) Do: Include the declaration-affecting parts of r.format and r.default in the generation, and add a test that redeclares a previously visited row with changed format and default.PR description / Title and description (pull_request_target)fails on this head and passes on the base branch: Failing after 7s.Should fix (1): not blocking, but worth doing before merging.
game/mods/menu/test/menu.test.ts:1080: The new test counts row reads across the whole switch and does not check that they happen before the drawing frame. (more on the line) Do: Record reads frame by frame on a revisited page and assert that its rows are read before its first drawing frame.@fixcan do L1, L2 and L3.Questions (1) (not confirmed from the code; they don't hold the recommendation)
More: does it help, other systems, switches, what was read
Does it help: Unproven. The reported debug fake-game minimum fell from 4.49 ms to 1.61 ms, but the results are least-of-five samples from different jobs, with no interleaved runs or spread, and do not measure the player-visible game.
Other systems: The menu runs on Windows and Linux and uses declarations from system and third-party mods. The headless Linux run stepped through the tabs but could not show their rendered contents; language changes and visible page switching remain untested.
Switches: None added, changed, or removed.
Reviewed:
1dcf4b82bcagainst12f42db5c1: Read the repository rules, contribution standards, PR template, diff, commit, view.ts, and the changed settings-host and menu paths with their callers and data structures. Skimmed the remaining portions of the larger changed files and their tests; output truncation prevented a full read of those files. Tooling's adjacent AGENTS.md and docs/review-checklist.md were absent.; nothing run (a code review).Checked and fine:
Testing: No commands from the project were run. The author reports passing menu and settings-host tests and a headless Linux smoke run; the supplied CI reports a PR-description check failure on this head.
Overlaps and merge order: None identified from the supplied context.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -197,2 +198,3 @@// moves it on, so the menu's kept pages are laid out again)for r in rows.iter().filter(|r| placed(r)) {(&r.mod_id, &r.key, &r.label, kind_name_of(&r.kind)).hash(&mut h);(&r.mod_id, &r.key, &r.label, &r.help, format!("{:?}", r.kind), r.restart, r.preset_exempt).hash(&mut h);L1 (blocking): The generation omits the declaration's format and default, although the cached declaration contains both.
When: If a mod redeclares a slider with the same key, label, kind and placement but changes its unit or display scale, service_decl_json returns the new format while generation_of remains unchanged. A previously visited page retains the old unit or scale and displays the slider incorrectly; a changed default is likewise retained.
Do: Include the declaration-affecting parts of r.format and r.default in the generation, and add a test that redeclares a previously visited row with changed format and default.
@ -1038,0 +1077,4 @@await switchTo("graphics");const again = await switchTo("audio");assert.equal(again.decls, 0, "shown again: its declarations as laid out before");assert.ok(again.rows > 0, "its rows read again");L2 (should fix): The new test counts row reads across the whole switch and does not check that they happen before the drawing frame.
When: Removing the early rowsOf(keys) call while keeping the declaration cache still reads the rows on the drawing frame. The test's rows > 0 assertion passes even though the change's key scheduling improvement is gone.
Do: Record reads frame by frame on a revisited page and assert that its rows are read before its first drawing frame.
Thanks. L1 fixed in
656c1a57: the generation now hashes each row's format (unit, display scale, default text) and default, with a test that a row declared again with another unit, scale or default moves it on. L2 fixed: the revisit test steps frame by frame and asserts the Audio tab's rows are read in a frame before the one that first draws it, and none in that frame. L3: Measurements' columns now name their commits (mod-api @12f42db5, this PR @1dcf4b82). On the question: the two sides came from separate jobs, not interleaved; the description now says so.