Rust allocations through mimalloc (+2 fps on an RTX 4090) #11

Closed
github-bot wants to merge 2 commits from github-bot/gh-11 into main AGit
Owner

@⁠Dastano on GitHub · 2026-11-26 20:54 UTC · original
Dastano:perf/mimalloc → main · +47 −4 · 7 files · 2 commits · closed without merging

Rust-side allocations go through mimalloc instead of the Windows process heap. On by default for the victory app (feature mimalloc); --no-default-features gives the old behaviour.

Why

A sampling profile (VICTORY_PROFILE, symbolized against the diag PDB) of the jail scene shows the thread that submits (victory-submit, the frame's critical path) spending about 15 % of its samples in the process heap (ntdll under realloc/alloc): vectors that grow on every submission in Host::submit, shadow::word_runs_avx2, Shadow::merge_under_writes, watch::writes, card_steps::does_of. That heap is shared with the title and the drivers. mimalloc keeps per-thread caches and grows blocks in place more often.

What changes

  • crates/victory-gpu: optional dependency mimalloc, feature mimalloc. Release builds with it set mimalloc::MiMalloc as the global allocator; diagnostics builds keep copystat's counting allocator, which then forwards to mimalloc instead of System (the counters stay as they are).
  • crates/victory-hle, apps/victory: the feature passed through; apps/victory has it on by default.

Measured

RTX 4090 24 GB (driver 621.14), Ryzen 9 7950X3D, 32 GB, Windows 11, title 1.0.2.1. scripts/play-nvidia.ps1 defaults (Series S, half render scale), diag build, warm pipeline cache, the same unattended route each run (Enter through the start screens, 420 s); figures are the jail scene, last 2 minutes of 5-s fps lines:

Build fps mean fps min preparing ms/frame
process heap (4 runs) 24.2 - 24.7 22.6 - 24.0 29.9 - 30.2
mimalloc, run 1 26.9 26.0 26.7
mimalloc, run 2 26.9 25.6 26.8

About +2 fps (+9 %), preparing about 3 ms shorter a frame. Screenshots of the same moments show no change in the picture. Built and checked: cargo build --locked --profile diag -p victory --features diagnostics, cargo build --locked --release -p victory, cargo test -p victory-gpu --features "diagnostics mimalloc" --lib copystat.

The build now compiles mimalloc's C sources (through cc, with the MSVC tools the build already needs).

🤖 Generated with Claude Code

**@⁠Dastano** on GitHub · 2026-11-26 20:54 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/11) `Dastano:perf/mimalloc` → `main` · +47 −4 · 7 files · 2 commits · closed without merging Rust-side allocations go through [mimalloc](https://github.com/microsoft/mimalloc) instead of the Windows process heap. On by default for the `victory` app (feature `mimalloc`); `--no-default-features` gives the old behaviour. ## Why A sampling profile (`VICTORY_PROFILE`, symbolized against the diag PDB) of the jail scene shows the thread that submits (`victory-submit`, the frame's critical path) spending about **15 % of its samples in the process heap** (`ntdll` under `realloc`/`alloc`): vectors that grow on every submission in `Host::submit`, `shadow::word_runs_avx2`, `Shadow::merge_under_writes`, `watch::writes`, `card_steps::does_of`. That heap is shared with the title and the drivers. mimalloc keeps per-thread caches and grows blocks in place more often. ## What changes - `crates/victory-gpu`: optional dependency `mimalloc`, feature `mimalloc`. Release builds with it set `mimalloc::MiMalloc` as the global allocator; diagnostics builds keep `copystat`'s counting allocator, which then forwards to mimalloc instead of `System` (the counters stay as they are). - `crates/victory-hle`, `apps/victory`: the feature passed through; `apps/victory` has it on by default. ## Measured RTX 4090 24 GB (driver 621.14), Ryzen 9 7950X3D, 32 GB, Windows 11, title 1.0.2.1. `scripts/play-nvidia.ps1` defaults (Series S, half render scale), diag build, warm pipeline cache, the same unattended route each run (Enter through the start screens, 420 s); figures are the jail scene, last 2 minutes of 5-s fps lines: | Build | fps mean | fps min | preparing ms/frame | |---|---|---|---| | process heap (4 runs) | 24.2 - 24.7 | 22.6 - 24.0 | 29.9 - 30.2 | | mimalloc, run 1 | 26.9 | 26.0 | 26.7 | | mimalloc, run 2 | 26.9 | 25.6 | 26.8 | About +2 fps (+9 %), preparing about 3 ms shorter a frame. Screenshots of the same moments show no change in the picture. Built and checked: `cargo build --locked --profile diag -p victory --features diagnostics`, `cargo build --locked --release -p victory`, `cargo test -p victory-gpu --features "diagnostics mimalloc" --lib copystat`. The build now compiles mimalloc's C sources (through `cc`, with the MSVC tools the build already needs). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The submitting thread, the frame's critical path, spent ~15 % of its samples
in the process heap (ntdll under realloc/alloc: vectors growing in
Host::submit, word_runs_avx2, merge_under_writes, watch::writes). That heap is
shared with the title and the drivers. With the `mimalloc` feature the Rust
side allocates through mimalloc instead (diagnostics builds keep counting
every block in copystat's allocator, which then forwards to mimalloc).

RTX 4090, Ryzen 9 7950X3D, Series S, half scale, play-nvidia.ps1 defaults,
same unattended route (tools/rtx4090/bench.ps1), jail scene, last 2 minutes:
  process heap: 24.7 fps (min 23.8), preparing 30.1 ms a frame
  mimalloc:     26.9 fps (min 26.0), preparing 26.9 ms a frame
No change in the picture.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 20:57:32 +00:00
github-bot closed this pull request 2026-11-27 00:42:57 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.