Run: let go of the executable's bytes once it is loaded (228 MB RAM) #2149

Closed
desplmfao wants to merge 1 commit from upstream-pr/2151 into main
desplmfao commented 2026-11-25 06:19:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by desplmfao on 2026-11-25T06:19:11Z.


Problem

run() reads the executable into a Vec (original) and makes a patched copy of it for the loader (prepared.bytes). Both are locals of run(), which only returns when the title exits. So the process keeps two copies of the executable in memory for the whole run, although after victory_loader::load the patched copy is on disk and loaded, and neither buffer is used again.

For Grand Theft Auto VI (Series X 1.0.2.1) the executable is 114 MB, so that's 228 MB held for nothing.

Change

drop((original, prepared)) right after victory_loader::load. Nothing after that point uses either. image doesn't borrow them; the compiler would refuse the drop if it did.

Measured

Allocations of 1 MiB or more tracked by call site, with a counting global allocator (diagnostics only, not part of this PR). RTX 5080, Linux, proton-cachyos 11.0:

live in the menu before after
std::fs::read in run() 114 MB 0
victory_loader::prepare 114 MB 0
VIctory's whole Rust heap 1,092 MB 863 MB

Tested

  • cargo clippy -p victory --all-targets -- -D warnings: clean.
  • The game runs into the world as before.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6598515085 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2151). Originally posted by [desplmfao](https://github.com/desplmfao) on 2026-11-25T06:19:11Z. --- ## Problem `run()` reads the executable into a `Vec` (`original`) and makes a patched copy of it for the loader (`prepared.bytes`). Both are locals of `run()`, which only returns when the title exits. So the process keeps **two copies of the executable** in memory for the whole run, although after `victory_loader::load` the patched copy is on disk and loaded, and neither buffer is used again. For Grand Theft Auto VI (Series X 1.0.2.1) the executable is 114 MB, so that's 228 MB held for nothing. ## Change `drop((original, prepared))` right after `victory_loader::load`. Nothing after that point uses either. `image` doesn't borrow them; the compiler would refuse the drop if it did. ## Measured Allocations of 1 MiB or more tracked by call site, with a counting global allocator (diagnostics only, not part of this PR). RTX 5080, Linux, proton-cachyos 11.0: | live in the menu | before | after | |---|---|---| | `std::fs::read` in `run()` | 114 MB | 0 | | `victory_loader::prepare` | 114 MB | 0 | | VIctory's whole Rust heap | 1,092 MB | 863 MB | ## Tested - `cargo clippy -p victory --all-targets -- -D warnings`: clean. - The game runs into the world as before. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-25 07:02:54 +00:00
DenRakEiw commented 2026-11-25 07:02:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T06:23:55Z.

Review: APPROVED


Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory — 12 passed, 0 failed
  • cargo clippy -p victory --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean drop of raw executable bytes after loading. Note for triage: #2071 makes the same change in apps/victory/src/run.rs.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6052793067 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2151#pullrequestreview-6052793067). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T06:23:55Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, Rust 1.98.1 MSVC): - `cargo test -p victory` — 12 passed, 0 failed - `cargo clippy -p victory --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean drop of raw executable bytes after loading. Note for triage: #2071 makes the same change in `apps/victory/src/run.rs`. AI-assisted (Gemini 4 Neon).
catminou4 commented 2026-11-25 07:02:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T06:33:09Z.

Review: COMMENTED


Static review only: apps/victory is Windows-only (Win32/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Executable bytes released once loaded (228 MB) — memory-footprint fix; possible duplicate of #2071 (same 'free executable bytes after mapping' change); maintainer should pick one.

<!-- greyfinch-sync:Marvisak/VIctory:review:6052889963 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2151#pullrequestreview-6052889963). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T06:33:09Z. **Review:** COMMENTED --- Static review only: apps/victory is Windows-only (Win32/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Executable bytes released once loaded (228 MB) — memory-footprint fix; **possible duplicate of #2071** (same 'free executable bytes after mapping' change); maintainer should pick one.
desplmfao commented 2026-11-25 07:03:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by desplmfao on 2026-11-25T06:25:12Z.


Closing as a duplicate of #2071, which makes the same change and came first. I missed it when I searched. For #2071, the measurement from here: tracking allocations of 1 MiB or more by call site in Grand Theft Auto VI, the two 114 MB blocks (std::fs::read in run() and victory_loader::prepare) are gone, and VIctory's heap in the menu goes from 1,092 to 863 MB. RTX 5080, Linux, proton-cachyos 11.0.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7154771107 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2151#issuecomment-7154771107). Originally posted by [desplmfao](https://github.com/desplmfao) on 2026-11-25T06:25:12Z. --- Closing as a duplicate of #2071, which makes the same change and came first. I missed it when I searched. For #2071, the measurement from here: tracking allocations of 1 MiB or more by call site in Grand Theft Auto VI, the two 114 MB blocks (`std::fs::read` in `run()` and `victory_loader::prepare`) are gone, and VIctory's heap in the menu goes from 1,092 to 863 MB. RTX 5080, Linux, proton-cachyos 11.0.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!2149
No description provided.