[PR #237] [MERGED] perf: reuse renderer entity material batching buffers #2427

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/237
Author: @rdbtCVS
Created: 10/14/2026
Status: ✅ Merged
Merged: 10/15/2026
Merged by: @ludovic111

Base: main ← Head: perf/entity-material-buckets-20261014


📝 Commits (1)

  • 2491d49 perf: reuse entity material batching scratch buffers

📊 Changes

2 files changed (+245 additions, -37 deletions)

View changed files

📝 crates/horizon-client/src/gfx.rs (+16 -37)
➕ crates/horizon-client/src/gfx/entity_batch.rs (+229 -0)

📄 Description

The renderer allocates a combined entity vertex Vec and scans entity quads four times each frame. Keep renderer-owned combined storage and reusable material index buckets, classify once, and copy vertices into active output slots. Uniform-material geometry uses a bulk copy. Material order, order within each material, unknown-layer fallback, incomplete entity tails, and additive/hand append behavior match the original helper.

Validation:

  • Byte-for-byte comparison against the original helper, including differing vertex attributes, first-vertex material classification, growing/shrinking/empty frames, incomplete entity/additive/hand tails, and stable buffer capacities/pointer after warmup.
  • 8 renderer tests and the new equivalence/reuse test pass.
  • cargo fmt --all -- --check, cargo clippy -p horizon-client --lib --tests --profile fast -- -D warnings, and git diff --check pass.
  • Production renderer/library compiled with the fast profile; no GPU visual/FPS benchmark performed.

Production-helper CPU benchmark, AMD Ryzen 5 5600X / Linux x86_64 / rustc 1.99.0, optimized fast profile, synthetic 36-byte Vertex geometry, 16 additive + 8 hand quads. Same inputs for the original helper and production EntityBatch, byte-equivalence checked, black_box, 50 warmup iterations, median of 15 samples of 100 frames. Compilation/checks completed before the reported benchmark.

Entity quads / materials Original Reused Speedup
65,536 / alternating materials 464.638 µs 501.036 µs 0.93x
65,536 / single material 497.752 µs 300.380 µs 1.66x
65,536 / repeated runs (normal16, glint4, overlay4, shadow2) 481.553 µs 470.551 µs 1.02x
262,144 / alternating materials 6.971359 ms 6.205413 ms 1.12x
262,144 / single material 6.401928 ms 2.874512 ms 2.23x

Limits/tradeoffs: the smaller alternating-material workload regresses about 8%; the realistic run case is near parity, while the large mixed case and uniform-material cases improve. These are isolated CPU measurements, not startup or FPS claims; prepared production assets were unavailable. Four initialized index arrays each retain the maximum observed quad count (32 bytes per peak quad on x86_64), and the combined Vec retains its peak capacity. Reported retained scratch is 11,537,792 bytes at 65,536 quads and 46,140,800 bytes at 262,144 quads. Initial allocation/new peaks initialize storage; warmed frames do not grow buffers, and every active output vertex is overwritten before upload.

Reproduce with:

CARGO_TARGET_DIR=/home/bob/Documents/horizon/target CARGO_INCREMENTAL=0 cargo test -p horizon-client --lib --profile fast gfx::entity_batch::tests -- --include-ignored --nocapture
CARGO_TARGET_DIR=/home/bob/Documents/horizon/target CARGO_INCREMENTAL=0 cargo test -p horizon-client --lib --profile fast gfx::tests::

🔄 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/237 **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/entity-material-buckets-20261014` --- ### 📝 Commits (1) - [`2491d49`](https://github.com/horizon-rust/horizon/commit/2491d49bf5d3e238b45e78095f1ce68d1bf7e0aa) perf: reuse entity material batching scratch buffers ### 📊 Changes **2 files changed** (+245 additions, -37 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/gfx.rs` (+16 -37) ➕ `crates/horizon-client/src/gfx/entity_batch.rs` (+229 -0) </details> ### 📄 Description The renderer allocates a combined entity vertex Vec and scans entity quads four times each frame. Keep renderer-owned combined storage and reusable material index buckets, classify once, and copy vertices into active output slots. Uniform-material geometry uses a bulk copy. Material order, order within each material, unknown-layer fallback, incomplete entity tails, and additive/hand append behavior match the original helper. Validation: - Byte-for-byte comparison against the original helper, including differing vertex attributes, first-vertex material classification, growing/shrinking/empty frames, incomplete entity/additive/hand tails, and stable buffer capacities/pointer after warmup. - 8 renderer tests and the new equivalence/reuse test pass. - `cargo fmt --all -- --check`, `cargo clippy -p horizon-client --lib --tests --profile fast -- -D warnings`, and `git diff --check` pass. - Production renderer/library compiled with the fast profile; no GPU visual/FPS benchmark performed. Production-helper CPU benchmark, AMD Ryzen 5 5600X / Linux x86_64 / rustc 1.99.0, optimized fast profile, synthetic 36-byte Vertex geometry, 16 additive + 8 hand quads. Same inputs for the original helper and production EntityBatch, byte-equivalence checked, black_box, 50 warmup iterations, median of 15 samples of 100 frames. Compilation/checks completed before the reported benchmark. | Entity quads / materials | Original | Reused | Speedup | | --- | ---: | ---: | ---: | | 65,536 / alternating materials | 464.638 µs | 501.036 µs | 0.93x | | 65,536 / single material | 497.752 µs | 300.380 µs | 1.66x | | 65,536 / repeated runs (normal16, glint4, overlay4, shadow2) | 481.553 µs | 470.551 µs | 1.02x | | 262,144 / alternating materials | 6.971359 ms | 6.205413 ms | 1.12x | | 262,144 / single material | 6.401928 ms | 2.874512 ms | 2.23x | Limits/tradeoffs: the smaller alternating-material workload regresses about 8%; the realistic run case is near parity, while the large mixed case and uniform-material cases improve. These are isolated CPU measurements, not startup or FPS claims; prepared production assets were unavailable. Four initialized index arrays each retain the maximum observed quad count (32 bytes per peak quad on x86_64), and the combined Vec retains its peak capacity. Reported retained scratch is 11,537,792 bytes at 65,536 quads and 46,140,800 bytes at 262,144 quads. Initial allocation/new peaks initialize storage; warmed frames do not grow buffers, and every active output vertex is overwritten before upload. Reproduce with: ```sh CARGO_TARGET_DIR=/home/bob/Documents/horizon/target CARGO_INCREMENTAL=0 cargo test -p horizon-client --lib --profile fast gfx::entity_batch::tests -- --include-ignored --nocapture CARGO_TARGET_DIR=/home/bob/Documents/horizon/target CARGO_INCREMENTAL=0 cargo test -p horizon-client --lib --profile fast gfx::tests:: ``` --- <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#2427
No description provided.