perf(hle,formats,loader): reclaim xmem pages, fix DirectStorage HoL, reuse audio scratch, and cut lock contention #526

Open
github-bot wants to merge 1 commit from github-bot/gh-526 into main AGit
Owner

@⁠ZerefDragnee1l on GitHub · 2026-12-06 01:54 UTC · original
ZerefDragnee1l:perf/hle-xmem-dstorage-audio-and-loader → main · +1711 −512 · 22 files · 1 commits · open

Splits the HLE, media format decoding, prompt validation, and loader optimizations out of #408 onto current main.

Summary

  • crates/larp-hle/src/modules/xmem.rs: Safely recycle freed page place slices after last unmap, switch non-alias allocations to SEC_RESERVE on demand, and drop the PHYSICAL mutex across title_memory_remapping.
  • crates/larp-hle/src/modules/dstorage.rs: Prevent Head-of-Line queue stalls on tight staging budgets (start_bypasses_head_of_line_blocking_across_lanes_and_allows_first_large_request), release staging before mip landing, reuse thread-local scratch buffers, and reserve headroom in default worker count.
  • Audio & format decoding (bcpack.rs, texture.rs, files.rs, apu.rs, audio.rs, dsp.rs, xma.rs): Reuse thread-local/voice scratch buffers, remove inner FFT/ring modulo division, preserve XMA2 overlap half-frames on bad frames, speed up bitreader/IMDCT butterflies, and lock-free skip idle Xma::pump slots.
  • Storage, async & game saves (storage.rs, xasync.rs, xgamesave.rs): Cache storage::used_bytes via Win32 directory change notifications, coalesce delayed XAsync tasks onto a shared timer thread with pool wakeup tracking, and use RwLock + background SaveWorker in xgamesave.
  • Host, input, UI settings, loader & prompts (host.rs, theme.rs, gameinput/{sdl,playstation}.rs, settings/{menu,look,extra}.rs, tls_watch.rs, console_insn.rs, prompts/hook.rs): Drop MODULES lock across LoadLibraryExA, cache DWM dark-mode state, throttle SDL plug polling + dirty-checked rumble, cache DualSense trigger env, add lock-free closed-menu fast path & OnceLock GDI/path caches, make TLS watch opt-in (LARP_TLS_WATCH=1), expand VirtualQuery cache to 16 slots, and validate prompts/hook movies in-place before boxing.

Verification

  • git diff --check -> clean
  • cargo check -p larp -> exited 0
  • cargo test -p larp-formats --lib -> 36 passed; 0 failed; 4 ignored (benchmarks / external reference streams ignored by #[ignore])
  • cargo test -p larp-hle --lib -- --skip look_picture -> 79 passed; 0 failed; 3 ignored; 1 filtered out (connected pad hardware tests and single-thread timing benchmark ignored by #[ignore]; look_picture skipped)
**@⁠ZerefDragnee1l** on GitHub · 2026-12-06 01:54 UTC · [original](https://github.com/gamingwithhomie/larp/pull/526) `ZerefDragnee1l:perf/hle-xmem-dstorage-audio-and-loader` → `main` · +1711 −512 · 22 files · 1 commits · open Splits the HLE, media format decoding, prompt validation, and loader optimizations out of #408 onto current `main`. ### Summary - **`crates/larp-hle/src/modules/xmem.rs`**: Safely recycle freed page place slices after last unmap, switch non-alias allocations to `SEC_RESERVE` on demand, and drop the `PHYSICAL` mutex across `title_memory_remapping`. - **`crates/larp-hle/src/modules/dstorage.rs`**: Prevent Head-of-Line queue stalls on tight staging budgets (`start_bypasses_head_of_line_blocking_across_lanes_and_allows_first_large_request`), release staging before mip landing, reuse thread-local scratch buffers, and reserve headroom in default worker count. - **Audio & format decoding (`bcpack.rs`, `texture.rs`, `files.rs`, `apu.rs`, `audio.rs`, `dsp.rs`, `xma.rs`)**: Reuse thread-local/voice scratch buffers, remove inner FFT/ring modulo division, preserve XMA2 overlap half-frames on bad frames, speed up bitreader/IMDCT butterflies, and lock-free skip idle `Xma::pump` slots. - **Storage, async & game saves (`storage.rs`, `xasync.rs`, `xgamesave.rs`)**: Cache `storage::used_bytes` via Win32 directory change notifications, coalesce delayed `XAsync` tasks onto a shared timer thread with pool wakeup tracking, and use `RwLock` + background `SaveWorker` in `xgamesave`. - **Host, input, UI settings, loader & prompts (`host.rs`, `theme.rs`, `gameinput/{sdl,playstation}.rs`, `settings/{menu,look,extra}.rs`, `tls_watch.rs`, `console_insn.rs`, `prompts/hook.rs`)**: Drop `MODULES` lock across `LoadLibraryExA`, cache DWM dark-mode state, throttle SDL plug polling + dirty-checked rumble, cache DualSense trigger env, add lock-free closed-menu fast path & `OnceLock` GDI/path caches, make TLS watch opt-in (`LARP_TLS_WATCH=1`), expand `VirtualQuery` cache to 16 slots, and validate `prompts/hook` movies in-place before boxing. ### Verification - `git diff --check` -> clean - `cargo check -p larp` -> exited 0 - `cargo test -p larp-formats --lib` -> `36 passed; 0 failed; 4 ignored` (benchmarks / external reference streams ignored by `#[ignore]`) - `cargo test -p larp-hle --lib -- --skip look_picture` -> `79 passed; 0 failed; 3 ignored; 1 filtered out` (connected pad hardware tests and single-thread timing benchmark ignored by `#[ignore]`; `look_picture` skipped)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-06 02:00:23 +00:00
Author
Owner

@⁠TrinityForever15 on GitHub · 2026-12-06 03:17 UTC · original

Tested on RX 6650 XT + Ryzen 5 9600X with NVMe, LARP_DSTORAGE_STAGING_MB=64. Together with #392 it removed the streaming hitches during open-world chases. https://github.com/iceboerg00/larp-amd/issues/64

**@⁠TrinityForever15** on GitHub · 2026-12-06 03:17 UTC · [original](https://github.com/gamingwithhomie/larp/pull/526#issuecomment-7450573276) Tested on RX 6650 XT + Ryzen 5 9600X with NVMe, `LARP_DSTORAGE_STAGING_MB=64`. Together with #392 it removed the streaming hitches during open-world chases. https://github.com/iceboerg00/larp-amd/issues/64
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/526/head:github-bot/gh-526'
git switch 'github-bot/gh-526'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-526'
git switch 'github-bot/gh-526'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-526'
git switch 'github-bot/gh-526'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-526'
git switch 'main'
git merge --squash 'github-bot/gh-526'
git switch 'main'
git merge --ff-only 'github-bot/gh-526'
git switch 'main'
git merge 'github-bot/gh-526'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.