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

Closed
github-bot wants to merge 1 commit from gh-pr/2151/head into gh-pr/2151/base
Owner

@⁠desplmfao on GitHub · 2026-11-25 06:19 UTC · original
desplmfao:fix/drop-image-buffers → main · +3 −0 · 1 files · 1 commits · closed without merging

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

**@⁠desplmfao** on GitHub · 2026-11-25 06:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2151) `desplmfao:fix/drop-image-buffers` → `main` · +3 −0 · 1 files · 1 commits · closed without merging ## 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)
run() read the executable into memory and made a patched copy of it for
the loader, and held both until the title exited: twice the executable
for the whole run (228 MB with Grand Theft Auto VI's 114 MB). Both are
on disk and loaded by then.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:56:15 +00:00
github-bot closed this pull request 2026-11-26 04:56:15 +00:00
Author
Owner

@⁠desplmfao on GitHub · 2026-11-25 06:25 UTC · original

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.

**@⁠desplmfao** on GitHub · 2026-11-25 06:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2151#issuecomment-7154771107) 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

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2151
No description provided.