[PR #240] [MERGED] perf: reuse entity geometry vertex storage between frames #2429

Closed
opened 2026-11-02 15:56:01 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/240
Author: @rdbtCVS
Created: 10/14/2026
Status: ✅ Merged
Merged: 10/15/2026
Merged by: @ludovic111

Base: main ← Head: perf/reuse-entity-geometry-20261014


📝 Commits (2)

  • 90bdf5b perf: retain entity geometry vertex storage between frames
  • a794c05 bench: measure dense entity geometry buffer reuse

📊 Changes

2 files changed (+164 additions, -9 deletions)

View changed files

➕ crates/horizon-client/examples/entity_geometry_bench.rs (+140 -0)
📝 crates/horizon-client/src/game.rs (+24 -9)

📄 Description

Each drawn frame currently starts entity geometry with a fresh Vec<Vertex>, rebuilding its capacity before the synchronous renderer upload. Retain that vector in Game, clear it before every frame (including title/empty frames), and take it locally while geometry builders borrow the game. Restore the buffer after the renderer returns, including render errors and a missing renderer. Geometry generation, vertex ordering and renderer batching are unchanged.

The retained vector keeps its high-water capacity for the lifetime of Game; it trades memory retained between frames for eliminating repeated vertex-buffer growth. There are no recoverable early exits between taking and restoring the buffer. Panic recovery is outside this change.

Validation:

  • CARGO_TARGET_DIR=/home/bob/Documents/horizon/target CARGO_INCREMENTAL=0 cargo clippy --profile fast -p horizon-client --bin horizon-client --example entity_geometry_bench -- -D warnings passed (compiles the actual Game call sites).
  • CARGO_TARGET_DIR=/home/bob/Documents/horizon/target CARGO_INCREMENTAL=0 cargo fmt --all -- --check and git diff --check passed.
  • The committed benchmark checks byte-for-byte vertex equality against fresh buffers through populated → empty/reset → smaller → populated builds, with unchanged pointer and capacity after warmup; all assertions passed.

Reproduce the benchmark:

CARGO_INCREMENTAL=0 cargo build --profile fast -p horizon-client --example entity_geometry_bench
taskset -c 2 target/fast/examples/entity_geometry_bench

The benchmark runs the production mobs::render::draw builder on identical synthetic six-part cube models (144 vertices per entity). Prepared assets were unavailable. It excludes Game construction, animation setup, other entity types, other frame geometry and GPU work; it does not measure full-frame/FPS gains. Each path warms up separately, alternates order, black-boxes inputs/output, and reports the median of eleven batches. Environment: Ryzen 5 5600X, Linux x86_64, rustc 1.99.0, optimized fast profile, pinned CPU 2, no concurrent builds.

Synthetic contributors Vertices Fresh µs/frame Retained µs/frame Speedup Retained capacity bytes Paired speedup median (range)
32 4,608 31.178 30.928 1.008x 294,912 1.008x (1.003–1.015x)
256 36,864 250.576 248.928 1.007x 2,359,296 1.006x (1.004–1.025x)
1,024 147,456 1,004.442 995.878 1.009x 9,437,184 1.009x (0.700–1.173x)
4,096 589,824 6,036.314 4,002.697 1.508x 37,748,736 1.506x (1.024–1.543x)
8,192 1,179,648 11,389.164 8,028.964 1.419x 75,497,472 1.418x (1.405–1.735x)

Batches contain 1,000 / 390 / 97 / 40 / 40 frames respectively. Paired speedups compare each fresh/retained batch before sorting; the range reports all eleven pairs. All five fixture sizes passed byte equivalence and populated → empty/reset → smaller → populated pointer/capacity reuse assertions.

Two preceding pinned dense runs measured 4,096 contributors at 6,652.870 → 4,089.997 µs (1.627x) and 6,019.280 → 3,983.132 µs (1.511x); 8,192 at 11,448.649 → 8,048.785 µs (1.422x) and 11,355.112 → 8,038.788 µs (1.413x). These repeated dense results show a convincing runtime improvement within this isolated builder fixture. At 32–1,024 contributors, gains are small and timings vary; there is no convincing material runtime improvement demonstrated for those sizes. Ordinary desktop/background process activity was present, with no concurrent builds.

The dense cases represent aggregate geometry volumes from many rendered objects. They do not establish that 4,096 or 8,192 real mobs can all spawn or remain visible simultaneously. Retained high-water capacity for these dense fixtures is 36 / 72 MiB. There is no full-frame/FPS claim, and no formal significance test was performed. Zero vertex-buffer growth after warmup remains the objective benefit at every measured size; actual heap allocation calls are not instrumented.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/240 **Author:** [@rdbtCVS](https://github.com/rdbtCVS) **Created:** 10/14/2026 **Status:** ✅ Merged **Merged:** 10/15/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/reuse-entity-geometry-20261014` --- ### 📝 Commits (2) - [`90bdf5b`](https://github.com/horizon-rust/horizon/commit/90bdf5bb1a26413275d16eb3183e368d136640d9) perf: retain entity geometry vertex storage between frames - [`a794c05`](https://github.com/horizon-rust/horizon/commit/a794c054172ba4b68b910f5f75f08e16bf4101e4) bench: measure dense entity geometry buffer reuse ### 📊 Changes **2 files changed** (+164 additions, -9 deletions) <details> <summary>View changed files</summary> ➕ `crates/horizon-client/examples/entity_geometry_bench.rs` (+140 -0) 📝 `crates/horizon-client/src/game.rs` (+24 -9) </details> ### 📄 Description Each drawn frame currently starts entity geometry with a fresh `Vec<Vertex>`, rebuilding its capacity before the synchronous renderer upload. Retain that vector in `Game`, clear it before every frame (including title/empty frames), and take it locally while geometry builders borrow the game. Restore the buffer after the renderer returns, including render errors and a missing renderer. Geometry generation, vertex ordering and renderer batching are unchanged. The retained vector keeps its high-water capacity for the lifetime of `Game`; it trades memory retained between frames for eliminating repeated vertex-buffer growth. There are no recoverable early exits between taking and restoring the buffer. Panic recovery is outside this change. Validation: - `CARGO_TARGET_DIR=/home/bob/Documents/horizon/target CARGO_INCREMENTAL=0 cargo clippy --profile fast -p horizon-client --bin horizon-client --example entity_geometry_bench -- -D warnings` passed (compiles the actual Game call sites). - `CARGO_TARGET_DIR=/home/bob/Documents/horizon/target CARGO_INCREMENTAL=0 cargo fmt --all -- --check` and `git diff --check` passed. - The committed benchmark checks byte-for-byte vertex equality against fresh buffers through populated → empty/reset → smaller → populated builds, with unchanged pointer and capacity after warmup; all assertions passed. Reproduce the benchmark: ```sh CARGO_INCREMENTAL=0 cargo build --profile fast -p horizon-client --example entity_geometry_bench taskset -c 2 target/fast/examples/entity_geometry_bench ``` The benchmark runs the production `mobs::render::draw` builder on identical synthetic six-part cube models (144 vertices per entity). Prepared assets were unavailable. It excludes Game construction, animation setup, other entity types, other frame geometry and GPU work; it does not measure full-frame/FPS gains. Each path warms up separately, alternates order, black-boxes inputs/output, and reports the median of eleven batches. Environment: Ryzen 5 5600X, Linux x86_64, rustc 1.99.0, optimized fast profile, pinned CPU 2, no concurrent builds. | Synthetic contributors | Vertices | Fresh µs/frame | Retained µs/frame | Speedup | Retained capacity bytes | Paired speedup median (range) | | --- | --- | --- | --- | --- | --- | --- | | 32 | 4,608 | 31.178 | 30.928 | 1.008x | 294,912 | 1.008x (1.003–1.015x) | | 256 | 36,864 | 250.576 | 248.928 | 1.007x | 2,359,296 | 1.006x (1.004–1.025x) | | 1,024 | 147,456 | 1,004.442 | 995.878 | 1.009x | 9,437,184 | 1.009x (0.700–1.173x) | | 4,096 | 589,824 | 6,036.314 | 4,002.697 | 1.508x | 37,748,736 | 1.506x (1.024–1.543x) | | 8,192 | 1,179,648 | 11,389.164 | 8,028.964 | 1.419x | 75,497,472 | 1.418x (1.405–1.735x) | Batches contain 1,000 / 390 / 97 / 40 / 40 frames respectively. Paired speedups compare each fresh/retained batch before sorting; the range reports all eleven pairs. All five fixture sizes passed byte equivalence and populated → empty/reset → smaller → populated pointer/capacity reuse assertions. Two preceding pinned dense runs measured 4,096 contributors at 6,652.870 → 4,089.997 µs (1.627x) and 6,019.280 → 3,983.132 µs (1.511x); 8,192 at 11,448.649 → 8,048.785 µs (1.422x) and 11,355.112 → 8,038.788 µs (1.413x). These repeated dense results show a convincing runtime improvement within this isolated builder fixture. At 32–1,024 contributors, gains are small and timings vary; there is no convincing material runtime improvement demonstrated for those sizes. Ordinary desktop/background process activity was present, with no concurrent builds. The dense cases represent aggregate geometry volumes from many rendered objects. They do not establish that 4,096 or 8,192 real mobs can all spawn or remain visible simultaneously. Retained high-water capacity for these dense fixtures is 36 / 72 MiB. There is no full-frame/FPS claim, and no formal significance test was performed. Zero vertex-buffer growth after warmup remains the objective benefit at every measured size; actual heap allocation calls are not instrumented. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 15:56:01 +07:00
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#2429
No description provided.