fix(menu): cache settingsHost lookups, decls, and store notifications to clear 5ms system/menu faults #3098
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
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!3098
Loading…
Reference in a new issue
No description provided.
Delete branch "Jer9/Longshot:fix/menu-settingshost-perf"
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
What a player notices: Opening the Insert menu and switching tabs or submenus no longer triggers
system/menuscript-runtime faults (stopped after 3 faults in a minute), keeping the menu responsive without mid-session restarts.#2822), especially when opening the Insert menu or inspecting multi-stop sliders (pad_speaker_sync,output_res).Root Cause & Fix (
settings_host.rs,settings_link.rs,i18n.rs,store.ts,view.ts)settingsHost.textsFFI storm:Services::textspreviously calledlink::capabilities(),self.service_row(key),rules_text()(link::status(),with_facts()), andchoices_of()inside the per-value loop (102menu_capabilitiesFFI calls for a single 51-stoppad_speaker_syncslider). Hoisted lookups outside the loop (102 -> 1call).settingsHost.decls&rowsper-frame rebuilds: Cached smallsystem/menudecls()answers (Arc<serde_json::Value>clone on hit) per(mod_id, keys, pages)for the activegeneration, with a 16-entry limit. The generation also tracks missing devices and their saved names. Skippedrecordings::decls()unless the"recordings"page or a recording key is requested, translated directly inservice_decl_said/read_decls_said, and avoidedkey.to_owned()oni18n::text_for()cache hits.store.ts&view.tsallocations: DeduplicatedrowListenersper batch (changed,rowsChanged,step), only notified!fresh.has(k)whenloadingempties, added a single-pageonlyfast path inlaidOut(), and skippedshare(null, laid)whenp.before === null.Testing
HOS_FRAME_COST=1.confirm/back/tab_next).0[error] script runtime: the built-in mod system/menu faulted/stoppedlines inlongshot_log.txt.cargo test -p api --lib --locked -- settings_host:18 passed, 0 failed(includestexts_reads_capabilities_once_across_all_valueswhich fails onforge/mainwithgot 102calls).cargo test -p modtool --lib --locked --release -- the_typescript_system_mods_pass_their_tests:1 passed, 0 failed.cargo fmt --check&cargo clippy -p host-sys -p api --tests --locked --no-deps -- -D warnings:0 warnings.python -I -B tests/run_all.py --changed forge/main:5 passed, 0 failed, 1 skipped.Measurements
Measured standalone on Windows 11, AMD Ryzen AI 7 350 / Radeon 860M, windowed
1920x1080(100% render scale),HOS_FRAME_COST=1, opening the Insert menu and stepping across 5 tabs + submenus:Where it makes a difference
forge/main(b4d56f526)fix/menu-settingshost-perf(61d025d25)system/menu[error]faults / mod stops5.2 msCPU) / 0settingsHost.decls(1 call)4.9 mswall /2.5 msCPU2.2 mswall /1.6 msCPUsystem/menusingle-frame[warn]3.8 msCPU /5.6 mswall3.0 msCPU /3.1 mswall (0 after first open)acquire_cpu_msp99 / max4.226 / 8.335 ms3.043 / 7.630 msWhere it does NOT make a difference (within run-to-run variance)
forge/main(b4d56f526)fix/menu-settingshost-perf(61d025d25)HOS_FRAME_COSTservices.settings_host(full 5-tab sweep)577.1 us/frame552.9 us/frameChecklist
main(b4d56f526)settings_hosttexts_reads_capabilities_once_across_all_values, failing onmain, passing here)python -I -B tests/run_all.py --changed forge/mainpasses (5 passed, 0 failed, 1 skipped)mise run test/tests/run_all.pyon this branchAssisted-by: Antigravity (Gemini 4 Neon)
Co-Authored-By: Antigravity [email protected]
Tested in game: Windows 11 Radeon 860M 1920x1080 5-tab Insert menu sweep: 0 system/menu faults, decls -55.1% wall
WIP: fix(menu): cache settingsHost lookups, decls, and store notifications to clear 5ms system/menu faultsto fix(menu): cache settingsHost lookups, decls, and store notifications to clear 5ms system/menu faults@review
Recommendation: Request changes. The declaration cache can return outdated device choices, and it retains an unbounded number of caller-supplied requests. The reported menu improvement is promising, but repeated measurements are needed to establish its size.
The change reduces repeated settings lookups and menu notifications to prevent script faults when opening and navigating the Insert menu. It adds caches and batching that need tighter invalidation, memory limits, and test isolation.
Blocking (1): must change before merging.
game/crates/api/src/services/settings_host.rs:1463: The declaration cache is keyed by a generation that does not include the missing-device status or saved device name used to construct choices. (more on the line) Do: Invalidate declarations when the relevant missing-device status and saved names change, and notify subscribers to reread them; add a test covering a missing device followed by selecting an available one.Should fix (2): not blocking, but worth doing before merging.
game/crates/api/src/services/settings_host.rs:1481: The declaration cache has no entry or byte limit and retains arbitrary request keys until the generation changes. (more on the line) Do: Bound the cache by entries or bytes, or cache only a bounded set of canonical page requests; also discard a mod's entries when it stops.game/crates/host-sys/src/settings_link.rs:525: The new fake capability counter is shared by all test threads, so the new exact call-count assertions can include calls from unrelated tests. (more on the line) Do: Make the counter test-thread-local or isolate the measurement so other tests cannot increment it.Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
@fixdoes its part first: Limit caching to the menu call sites that need it, reducing the shared paths affected.)@fixcan do L1, L2, L3 and L5.Checks: Still running: 11 checks.
More: does it help, other systems, switches, what was read
Does it help: Unproven as a measured performance gain. The PR reports one Windows Radeon 860M menu sweep with faults falling from 1 to 0 and first-open declarations from 4.9 ms to 2.2 ms wall time; it does not report multiple interleaved runs or their spread. The added game-free test reports 102 capability calls on main and at most one here.
Other systems: The capabilities cache also serves settings validation, preset selection, startup facts, and the fallback menu on both Windows and Linux. Device changes and saved missing devices affect declaration choices independently of the cached generation. The supplied in-game run covers Windows on a Radeon APU; Linux and Tier 1 hardware results are not supplied.
Switches: None added, changed, or removed.
Reviewed:
61d025d251againstb4d56f5264: Read AGENTS.md, CONTRIBUTING.md, the PR template and docs/dev/standards.md; docs/review-checklist.md and ../Tooling/AGENTS.md were absent. Read the diff and changed code, tracing settings generation, device choices, settings validation, translations, recordings and store subscriptions. Skimmed related tests and renderer status references; did not read the entire renderer or all callers in full.; nothing run (a code review).Checked and fine:
Testing: Read-only review; no project code, tests, or scripts were run. The author reports game-free checks and a Windows in-game sweep; CI is still running.
Overlaps and merge order: Not checked: network is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -1356,0 +1460,4 @@let sv = self.settings_host.borrow();if sv.decls_gen == generation&& let Some(cached) = sv.decls_cache.get(&cache_key){L1 (blocking): The declaration cache is keyed by a generation that does not include the missing-device status or saved device name used to construct choices.
When: If declarations are read while the saved audio output is missing, then the player selects Default without changing the device list, the renderer clears the missing-output bit but the generation stays the same. A subsequent decls call returns the cached extra missing-device choice and its old range.
Do: Invalidate declarations when the relevant missing-device status and saved names change, and notify subscribers to reread them; add a test covering a missing device followed by selecting an available one.
@ -1356,0 +1478,4 @@sv.decls_cache.clear();sv.decls_gen = generation;}sv.decls_cache.insert(cache_key, out.clone());L2 (should fix): The declaration cache has no entry or byte limit and retains arbitrary request keys until the generation changes.
When: A system mod can repeatedly call decls with different valid key lists while the generation remains stable. Each call retains another key vector and JSON answer in host memory, so a long session can grow memory without bound even after the script releases its results.
Do: Bound the cache by entries or bytes, or cache only a bounded set of canonical page requests; also discard a mod's entries when it stops.
@ -504,3 +522,4 @@#[cfg(feature = "fake")]{*fake::lock(&fake::CAPS_ASKED) += 1;fake::lock(&fake::CAPS).clone()L3 (should fix): The new fake capability counter is shared by all test threads, so the new exact call-count assertions can include calls from unrelated tests.
When: When another API test calls capabilities between this test's reset and read, the counter exceeds the expected value and the test fails despite the implementation making the correct number of calls.
Do: Make the counter test-thread-local or isolate the measurement so other tests cannot increment it.
@fix
61d025d251e3c4432361Recommendation: Approve. The code is ready: only testing is left. The menu optimization remains in place, but its gain and menu-closed cost have not been established with repeated comparisons on the current head. The shared settings paths also still need coverage beyond the reported Windows APU run. Recommend approval; not approved on the forge.
What
@fixchangedI changed this pull request: the new head is
e3c4432361. I rebased it ontomain(0aeb685893). I edited its description to match the change.Changed
Changed in part (the rest is for the author)
Nothing was built or run: the checks run again on the new head.
The change reduces repeated settings lookups and allocations intended to prevent menu script faults. The fix bounds declaration caching, refreshes missing-device declarations and removes the shared capability snapshot cache; its performance after those edits remains unmeasured.
Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
Checks: they run again on this head; a failure shows on the pull request.
Also noticed (4; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Unproven on the current head. The description reports first-open declarations falling from 4.9 ms to 2.2 ms wall time and one menu fault falling to zero on a Windows Radeon 860M, but does not provide repeated comparisons after removal of the capability cache or a menu-closed comparison.
Other systems: Shared settings and menu paths run on Windows and Linux across GPUs, including Steam Deck. The reported Windows APU run does not establish behavior on the other requested platforms.
Switches: No switches added or changed by BeanBot's fix; the complete base diff includes changes outside the stated menu scope that were not fully reviewed.
Reviewed:
e3c4432361against0aeb685893: Read AGENTS.md, CONTRIBUTING.md, the pull request template, standards, the complete BeanBot fix diff, and the affected cache, generation, capability and mod-stop code. Inspected the menu-related base diff and searched missing-device callers. The supplied base diff also contains many unrelated files; those files and the full changed source files were not read in full. Tooling's adjacent AGENTS.md and docs/review-checklist.md were absent.; nothing run (a code review).Checked and fine:
Testing: No commands that build or run the project were executed. The supplied game and game-free results predate the untested fix; CI has not run on this head.
Overlaps and merge order: Not established from the supplied information.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.
HumanBean referenced this pull request2026-12-03 20:13:20 +00:00
llun referenced this pull request2026-12-03 20:16:18 +00:00
llun referenced this pull request2026-12-03 21:36:06 +00:00