[PR #2060] [MERGED] Creative inventory: keep its stacks, the items' level and their GUI vertices instead of redoing them every frame #3974

Closed
opened 2026-11-03 04:13:41 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/2060
Author: @kacpherek
Created: 10/26/2026
Status: ✅ Merged
Merged: 10/26/2026
Merged by: @ludovic111

Base: main ← Head: fix/1953-creative-menu-fps


📝 Commits (5)

  • fb9b26a Work out the creative grid's stacks once per tab or search, not every frame
  • 515c0bd Work out the level item models read once a frame
  • 0f65690 Draw a GUI item's vertices once while it stays in place
  • 5389f72 Creative: work out the shown items again after a resource or language reload
  • 2fc2ee1 Merge main (creative.rs: the search is an EditBox since #1990; the shown items key on its value)

📊 Changes

8 files changed (+207 additions, -21 deletions)

View changed files

📝 crates/horizon-assets/src/item_model.rs (+10 -7)
📝 crates/horizon-client/src/creative.rs (+70 -10)
📝 crates/horizon-client/src/game.rs (+11 -2)
📝 crates/horizon-client/src/game/item_draw.rs (+19 -1)
📝 crates/horizon-client/src/game/options.rs (+1 -0)
📝 crates/horizon-client/src/game/packs.rs (+2 -0)
📝 crates/horizon-client/src/item_render.rs (+4 -0)
📝 crates/horizon-client/src/item_render/gui.rs (+90 -1)

📄 Description

Fixes #1953.

What and why

The frame rate halved with the creative inventory open and fell further while searching. Most of the
frame went to work that gives the same result every frame. Three changes keep those results.

  1. The grid's stacks. draw_creative cloned every tab with its stacks twice a frame, and
    Creative::items cloned the selected tab's stacks on each of its three or four calls a frame. On the
    search tab each call ran the whole search again and built every stack's localised name. The grid's
    stacks are now worked out when the tab, the search text or the language changes, and the screen draws
    the tabs from headers without their stacks.
  2. The level an item model reads. draw_item_model built the client level state for every stack and
    sampled the sky each time, about seventy times a frame on this screen. It is now kept for the frame,
    keyed by frame, game time, day time and dimension.
  3. Each item's own drawing. ItemModels::components cloned the item's whole default component map on
    every resolve, though most stacks carry no patch. It now borrows the defaults and copies them only to
    apply a patch. gui::draw submitted, culled, sorted and clipped every quad of a static item again each
    frame. A generated item has hundreds of edge quads, and in the GUI all of them face sideways and get
    culled. The HUD vertices of a static item are now kept per GUI position and appended as they were. The
    key holds the item's baked models, tints and transforms, the atlas and the exact position, so the
    vertices are the ones gui::draw would produce. Items with a glint or a special model renderer are
    drawn as before.

Nothing on screen changes. Only the time the frame spends getting there changes.

Vanilla reference

  • CreativeModeInventoryScreen.selectTab fills menu.items once when a tab is selected.
    refreshSearchResults runs when the search box changes (charTyped, keyPressed), not from render.
    render and ItemPickerMenu.scrollTo only read menu.items.
  • GuiGraphics.renderItem calls ItemModelResolver.updateForTopItem(..., level, owner, seed), and every
    item of a frame reads the same ClientLevel.
  • ItemStack.getComponents reads the prototype and the patch without copying the prototype.

Measured

Same machine (i7-12700K, RTX 4070 SUPER, Windows), same new creative world (seed 1), vsync off, frame
limit off. Each number is the average fps over 5 seconds from horizon-ctl bench 5, release build.

The three builds below were measured one after another in the same session.

upstream/main 1+2 1+2+3
nothing open 1,793 1,796 1,811
creative inventory (Building Blocks) 689 947 1,407
Combat tab 650 908 1,348
search tab, after typing a 427 924 1,315

"Nothing open" varies by about 100 fps between runs, and none of the changes touch it.

HORIZON_SPIKES timings with the inventory open: the HUD took 0.66 ms of each frame on upstream/main, of
which 0.61 ms went to draw_item_model for about 70 stacks. With all three changes the HUD takes 0.23 ms,
and draw_item_model 0.16 ms, most of it model resolution (0.11 ms).

Harnesses, each script run directly, on changes 1 and 2 (before change 3):

  • test_creative_parity: 6793/6793 searches match; 12 tabs, 2000 search stacks; creative parity ok.
  • test_menu_click_parity: 8000/8000 cases match.

Change 3 touches ItemModels::components and gui::draw, which test_item_model_parity, test_hud_parity
and test_container_screen_parity cover. I did not finish those runs on this machine; they are for the
parity job.

Self-check

I did not paste a tools/pr_ready.py block: I work on Windows, where tools/parity.py cannot run (it needs
fcntl) and three horizon-client tests fail on upstream/main as well
(crash::tests::stacks_start_at_the_panicking_frame,
packs::cache::tests::directory_inputs_config_and_owned_output_recovery,
save::tests::session_lock_is_exclusive). cargo fmt --all -- --check passes; CI runs clippy and the
tests on Linux, and the harnesses above were run one by one (python tools/test_<name>_parity.py).


🔄 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/2060 **Author:** [@kacpherek](https://github.com/kacpherek) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 10/26/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/1953-creative-menu-fps` --- ### 📝 Commits (5) - [`fb9b26a`](https://github.com/horizon-rust/horizon/commit/fb9b26a06cf72d8d9f61fb260d9db76937623713) Work out the creative grid's stacks once per tab or search, not every frame - [`515c0bd`](https://github.com/horizon-rust/horizon/commit/515c0bdb7d4361d702eb583b6c8f627991705834) Work out the level item models read once a frame - [`0f65690`](https://github.com/horizon-rust/horizon/commit/0f6569070d13ba42d43db11711d62c572bf2b50d) Draw a GUI item's vertices once while it stays in place - [`5389f72`](https://github.com/horizon-rust/horizon/commit/5389f72b9a7479d791f66977a25b6bfd1bc5d9cb) Creative: work out the shown items again after a resource or language reload - [`2fc2ee1`](https://github.com/horizon-rust/horizon/commit/2fc2ee1e139df3b1e35899115b1e49143058aa56) Merge main (creative.rs: the search is an EditBox since #1990; the shown items key on its value) ### 📊 Changes **8 files changed** (+207 additions, -21 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-assets/src/item_model.rs` (+10 -7) 📝 `crates/horizon-client/src/creative.rs` (+70 -10) 📝 `crates/horizon-client/src/game.rs` (+11 -2) 📝 `crates/horizon-client/src/game/item_draw.rs` (+19 -1) 📝 `crates/horizon-client/src/game/options.rs` (+1 -0) 📝 `crates/horizon-client/src/game/packs.rs` (+2 -0) 📝 `crates/horizon-client/src/item_render.rs` (+4 -0) 📝 `crates/horizon-client/src/item_render/gui.rs` (+90 -1) </details> ### 📄 Description Fixes #1953. ## What and why The frame rate halved with the creative inventory open and fell further while searching. Most of the frame went to work that gives the same result every frame. Three changes keep those results. 1. The grid's stacks. `draw_creative` cloned every tab with its stacks twice a frame, and `Creative::items` cloned the selected tab's stacks on each of its three or four calls a frame. On the search tab each call ran the whole search again and built every stack's localised name. The grid's stacks are now worked out when the tab, the search text or the language changes, and the screen draws the tabs from headers without their stacks. 2. The level an item model reads. `draw_item_model` built the client level state for every stack and sampled the sky each time, about seventy times a frame on this screen. It is now kept for the frame, keyed by frame, game time, day time and dimension. 3. Each item's own drawing. `ItemModels::components` cloned the item's whole default component map on every resolve, though most stacks carry no patch. It now borrows the defaults and copies them only to apply a patch. `gui::draw` submitted, culled, sorted and clipped every quad of a static item again each frame. A generated item has hundreds of edge quads, and in the GUI all of them face sideways and get culled. The HUD vertices of a static item are now kept per GUI position and appended as they were. The key holds the item's baked models, tints and transforms, the atlas and the exact position, so the vertices are the ones `gui::draw` would produce. Items with a glint or a special model renderer are drawn as before. Nothing on screen changes. Only the time the frame spends getting there changes. ## Vanilla reference - `CreativeModeInventoryScreen.selectTab` fills `menu.items` once when a tab is selected. `refreshSearchResults` runs when the search box changes (`charTyped`, `keyPressed`), not from `render`. `render` and `ItemPickerMenu.scrollTo` only read `menu.items`. - `GuiGraphics.renderItem` calls `ItemModelResolver.updateForTopItem(..., level, owner, seed)`, and every item of a frame reads the same `ClientLevel`. - `ItemStack.getComponents` reads the prototype and the patch without copying the prototype. ## Measured Same machine (i7-12700K, RTX 4070 SUPER, Windows), same new creative world (seed 1), vsync off, frame limit off. Each number is the average fps over 5 seconds from `horizon-ctl bench 5`, release build. The three builds below were measured one after another in the same session. | | upstream/main | 1+2 | 1+2+3 | | --- | ---: | ---: | ---: | | nothing open | 1,793 | 1,796 | 1,811 | | creative inventory (Building Blocks) | 689 | 947 | 1,407 | | Combat tab | 650 | 908 | 1,348 | | search tab, after typing `a` | 427 | 924 | 1,315 | "Nothing open" varies by about 100 fps between runs, and none of the changes touch it. `HORIZON_SPIKES` timings with the inventory open: the HUD took 0.66 ms of each frame on upstream/main, of which 0.61 ms went to `draw_item_model` for about 70 stacks. With all three changes the HUD takes 0.23 ms, and `draw_item_model` 0.16 ms, most of it model resolution (0.11 ms). Harnesses, each script run directly, on changes 1 and 2 (before change 3): - `test_creative_parity`: 6793/6793 searches match; 12 tabs, 2000 search stacks; creative parity ok. - `test_menu_click_parity`: 8000/8000 cases match. Change 3 touches `ItemModels::components` and `gui::draw`, which `test_item_model_parity`, `test_hud_parity` and `test_container_screen_parity` cover. I did not finish those runs on this machine; they are for the parity job. ## Self-check I did not paste a `tools/pr_ready.py` block: I work on Windows, where `tools/parity.py` cannot run (it needs `fcntl`) and three horizon-client tests fail on upstream/main as well (`crash::tests::stacks_start_at_the_panicking_frame`, `packs::cache::tests::directory_inputs_config_and_owned_output_recovery`, `save::tests::session_lock_is_exclusive`). `cargo fmt --all -- --check` passes; CI runs clippy and the tests on Linux, and the harnesses above were run one by one (`python tools/test_<name>_parity.py`). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 04:13:41 +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#3974
No description provided.