[GH-ISSUE #2826] Renderer: staging memory grows without bound while mobs appear, until the game is OOM-killed #708

Closed
opened 2026-11-02 15:41:18 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @Nghiathan13 on GitHub (Oct 27, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/2826

🤖 Filed by Nghiathan13's AI agent (Claude Code), not by Nghiathan13.

What happens. With many mobs in view, Horizon's mapped staging memory grows by about 250 MB per second for as long as more mobs appear, and is never given back. On a 12 GB laptop the kernel killed the game at about 9 GB.

Mobs in view (summoned one by one) Mapped memory (RssShmem)
0 to ~830 77 MB, flat
~950 ~1.3 GB
~1,100 ~3 GB (stopped here by the test's own 3 GB guard)
~1,800, no guard ~9 GB, game OOM-killed

Environment

  • OS: Ubuntu 26.04.1 LTS (Linux)
  • CPU / RAM: AMD Ryzen 7 5800H, 12 GB
  • GPU: NVIDIA GeForce RTX 3050 Laptop, Vulkan, driver 595.99.02
  • Build: --profile fast, offscreen, render distance 12, uncapped frame rate
  • Guarded rows: main at d9b6483a (two runs) and 7d0ae565 (one run), the same curve each time
  • Unguarded row: an earlier run of a local build with an unrelated renderer change that uploads through the same belt

Repro. Creative world, render distance 12; summon NoAI mobs one by one in front of the camera, all within entity render distance (a 64 × 50 grid of mixed species, some in armour); watch RssShmem in /proc/<pid>/status.

Cause. gfx/upload.rs sends per-frame writes through a wgpu::util::StagingBelt with 1 MB chunks. A write larger than any kept chunk gets a new buffer of exactly its size, and the belt keeps every buffer forever. The entity batch is larger than 1 MB with a few hundred mobs and grows a little every frame while mobs appear, so it never fits the previous frame's buffer: one new buffer per frame, all kept.

Entity upload per frame Buffers kept by the belt
4 MB 2
8 MB 219
12 MB 598

Proposed fix. Stage writes larger than the chunk in a power-of-two allocation, copying only the bytes written, so the buffers the belt keeps get reused. A pull request with it, and a GPU test that fails on main, follows.

Originally created by @Nghiathan13 on GitHub (Oct 27, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/2826 > 🤖 Filed by Nghiathan13's AI agent (Claude Code), not by Nghiathan13. **What happens.** With many mobs in view, Horizon's mapped staging memory grows by about 250 MB per second for as long as more mobs appear, and is never given back. On a 12 GB laptop the kernel killed the game at about 9 GB. | Mobs in view (summoned one by one) | Mapped memory (`RssShmem`) | |---|---| | 0 to ~830 | 77 MB, flat | | ~950 | ~1.3 GB | | ~1,100 | ~3 GB (stopped here by the test's own 3 GB guard) | | ~1,800, no guard | ~9 GB, game OOM-killed | **Environment** - OS: Ubuntu 26.04.1 LTS (Linux) - CPU / RAM: AMD Ryzen 7 5800H, 12 GB - GPU: NVIDIA GeForce RTX 3050 Laptop, Vulkan, driver 595.99.02 - Build: `--profile fast`, offscreen, render distance 12, uncapped frame rate - Guarded rows: main at d9b6483a (two runs) and 7d0ae565 (one run), the same curve each time - Unguarded row: an earlier run of a local build with an unrelated renderer change that uploads through the same belt **Repro.** Creative world, render distance 12; summon NoAI mobs one by one in front of the camera, all within entity render distance (a 64 × 50 grid of mixed species, some in armour); watch `RssShmem` in `/proc/<pid>/status`. **Cause.** `gfx/upload.rs` sends per-frame writes through a `wgpu::util::StagingBelt` with 1 MB chunks. A write larger than any kept chunk gets a new buffer of exactly its size, and the belt keeps every buffer forever. The entity batch is larger than 1 MB with a few hundred mobs and grows a little every frame while mobs appear, so it never fits the previous frame's buffer: one new buffer per frame, all kept. | Entity upload per frame | Buffers kept by the belt | |---|---| | 4 MB | 2 | | 8 MB | 219 | | 12 MB | 598 | **Proposed fix.** Stage writes larger than the chunk in a power-of-two allocation, copying only the bytes written, so the buffers the belt keeps get reused. A pull request with it, and a GPU test that fails on main, follows.
Author
Owner

@Nghiathan13 commented on GitHub (Oct 27, 2026):

🤖 Agent: Nghiathan13 is taking this one, to avoid duplicate work. The fix (power-of-two staging in Uploads, with a GPU test that fails on main) is ready; a pull request follows shortly.

<!-- gh-comment-id:6443717566 --> @Nghiathan13 commented on GitHub (Oct 27, 2026): 🤖 Agent: Nghiathan13 is taking this one, to avoid duplicate work. The fix (power-of-two staging in `Uploads`, with a GPU test that fails on main) is ready; a pull request follows shortly.
Sign in to join this conversation.
No milestone
No project
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
horizon-rust/horizon#708
No description provided.