[PR #4068] [MERGED] Glint reads the clock and options once per frame, not per item #5395

Closed
opened 2026-11-03 05:12:19 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4068
Author: @d3grando
Created: 10/29/2026
Status: ✅ Merged
Merged: 10/30/2026
Merged by: @levzzz5154

Base: main ← Head: fix-3183


📝 Commits (1)

  • 5550a6c Read the glint clock and options once per frame, not per item

📊 Changes

3 files changed (+89 additions, -25 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+7 -2)
📝 crates/horizon-client/src/game/item_draw.rs (+19 -23)
📝 crates/horizon-client/src/item_render.rs (+63 -0)

📄 Description

🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando personally.

What and why

With thousands of dropped items on screen, the render thread read the clock once per item. On machines where the kernel falls back to the HPET clocksource, those reads took a large share of the frame.

Every item submitted to the world (submit_item_world, submit_item_lit, submit_item_unlit, item heads on armour stands) built its WorldSink with Game::glint(). That call read self.started.elapsed() and looked up glintSpeed and glintStrength by name through OptionsFile::double, which is a linear scan of the options table. It did this for every item, even ones with no foil. draw_item_model (GUI items) did the same for each item, and glint_ticks() read both again for the frame globals.

Vanilla doesn't work per item. GameRenderer.extract calls extractOptions() once per frame, which copies glintSpeed/glintStrength into OptionsRenderState. TextureTransform.setupGlintTexturing reads Util.getMillis() once per glint render-type batch.

The fix:

  • item_render::GlintFrame is a per-frame snapshot: clock millis, speed, strength, and whether the atlas has misc/enchanted_glint_item.
  • Game::render() captures it once at the start of every frame (capture_glint_frame).
  • glint(), the frame's glint_alpha/glint_ticks, and draw_item_model now read the snapshot. Per item it is a copy of a few floats.

The glint still moves every frame. Every item in a frame now shares one phase, as each glint batch does in vanilla.

Measured on Windows 11 (TSC clock, Ryzen 9800X3D), with the old per-item path and the new one in a release-profile loop of 1,000,000 calls: 77–97 ns per item before, 1–2.5 ns after. With 9610 frozen cobblestone drops in view (the issue's /fill … destroy scene, with /tick freeze so the scene is the same in both runs), the entity_geometry span (HORIZON_SPIKES=0) went from 19.0 ms to about 17.3–18.4 ms per frame. The machine was busy with other builds, so these numbers are noisy. On HPET, the issue measured ~1.6 µs per clock read, so the saving there is roughly 15 ms per frame for that scene.

Fixes #3183

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

Checked with javap on the 26.3 client jar:

  • GameRenderer.extract(DeltaTracker, boolean) → extractOptions(): stores Options.glintSpeed()/glintStrength() in OptionsRenderState.glintSpeed/glintStrength once per frame.
  • TextureTransform.setupGlintTexturing(float): Util.getMillis() * gameRenderState().optionsRenderState.glintSpeed * 8.0. It is reached through the glint render types' texture transform, once per batch, not per item. ItemEntityRenderer has no clock reads.

No parity harness covers glint timing. The unit test item_render::tests::a_frame_glint_is_shared_by_every_item checks the snapshot: the world glint comes out at scale 0.5, every item drawn from one frame gets the same glint UV, scroll_ticks matches Glint::scroll_ticks (123456 ms at speed 0.5 → 163824), and with the sprite missing there is no glint.

Self-check

Run on Windows 11. tools/pr_ready.py doesn't run on Windows, so I ran the steps by hand:

  • cargo fmt --all -- --check: clean
  • cargo clippy -p horizon-client --all-targets -- -D warnings: clean
  • cargo test -p horizon-client --lib item_render: 15 passed
  • cargo test -p horizon-client --bin horizon-client item_draw: 2 passed
  • The new test without the code change (with GlintFrame removed): it doesn't build (error[E0422]: cannot find struct ... GlintFrame). The game path can't be unit-tested because no test builds a Game, so the before/after evidence is the measurements above. With the change: a_frame_glint_is_shared_by_every_item ... ok.
  • cargo build --profile fast -p horizon-client --bins, single player on the server thread:
    • 9610 frozen drops in view: horizon-ctl bench and the entity_geometry spans as above.
    • An enchanted diamond sword (held and in the hotbar) and a dropped Protection IV chestplate still show the glint. The held sword's glint moves between two screenshots 0.6 s apart.

🤖 Generated with Claude Code


🔄 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/4068 **Author:** [@d3grando](https://github.com/d3grando) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `fix-3183` --- ### 📝 Commits (1) - [`5550a6c`](https://github.com/horizon-rust/horizon/commit/5550a6c3272b47e2d4d9ad97d7c8f56bfd53fbe8) Read the glint clock and options once per frame, not per item ### 📊 Changes **3 files changed** (+89 additions, -25 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+7 -2) 📝 `crates/horizon-client/src/game/item_draw.rs` (+19 -23) 📝 `crates/horizon-client/src/item_render.rs` (+63 -0) </details> ### 📄 Description > 🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando personally. ## What and why With thousands of dropped items on screen, the render thread read the clock once per item. On machines where the kernel falls back to the HPET clocksource, those reads took a large share of the frame. Every item submitted to the world (`submit_item_world`, `submit_item_lit`, `submit_item_unlit`, item heads on armour stands) built its `WorldSink` with `Game::glint()`. That call read `self.started.elapsed()` and looked up `glintSpeed` and `glintStrength` by name through `OptionsFile::double`, which is a linear scan of the options table. It did this for every item, even ones with no foil. `draw_item_model` (GUI items) did the same for each item, and `glint_ticks()` read both again for the frame globals. Vanilla doesn't work per item. `GameRenderer.extract` calls `extractOptions()` once per frame, which copies `glintSpeed`/`glintStrength` into `OptionsRenderState`. `TextureTransform.setupGlintTexturing` reads `Util.getMillis()` once per glint render-type batch. The fix: - `item_render::GlintFrame` is a per-frame snapshot: clock millis, speed, strength, and whether the atlas has `misc/enchanted_glint_item`. - `Game::render()` captures it once at the start of every frame (`capture_glint_frame`). - `glint()`, the frame's `glint_alpha`/`glint_ticks`, and `draw_item_model` now read the snapshot. Per item it is a copy of a few floats. The glint still moves every frame. Every item in a frame now shares one phase, as each glint batch does in vanilla. Measured on Windows 11 (TSC clock, Ryzen 9800X3D), with the old per-item path and the new one in a release-profile loop of 1,000,000 calls: **77–97 ns per item before, 1–2.5 ns after**. With 9610 frozen cobblestone drops in view (the issue's `/fill … destroy` scene, with `/tick freeze` so the scene is the same in both runs), the `entity_geometry` span (`HORIZON_SPIKES=0`) went from 19.0 ms to about 17.3–18.4 ms per frame. The machine was busy with other builds, so these numbers are noisy. On HPET, the issue measured ~1.6 µs per clock read, so the saving there is roughly 15 ms per frame for that scene. Fixes #3183 ## Kind - [ ] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [x] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference Checked with javap on the 26.3 client jar: - `GameRenderer.extract(DeltaTracker, boolean)` → `extractOptions()`: stores `Options.glintSpeed()`/`glintStrength()` in `OptionsRenderState.glintSpeed`/`glintStrength` once per frame. - `TextureTransform.setupGlintTexturing(float)`: `Util.getMillis() * gameRenderState().optionsRenderState.glintSpeed * 8.0`. It is reached through the glint render types' texture transform, once per batch, not per item. `ItemEntityRenderer` has no clock reads. No parity harness covers glint timing. The unit test `item_render::tests::a_frame_glint_is_shared_by_every_item` checks the snapshot: the world glint comes out at scale 0.5, every item drawn from one frame gets the same glint UV, `scroll_ticks` matches `Glint::scroll_ticks` (123456 ms at speed 0.5 → 163824), and with the sprite missing there is no glint. ## Self-check Run on Windows 11. `tools/pr_ready.py` doesn't run on Windows, so I ran the steps by hand: - `cargo fmt --all -- --check`: clean - `cargo clippy -p horizon-client --all-targets -- -D warnings`: clean - `cargo test -p horizon-client --lib item_render`: 15 passed - `cargo test -p horizon-client --bin horizon-client item_draw`: 2 passed - The new test without the code change (with `GlintFrame` removed): it doesn't build (`error[E0422]: cannot find struct ... GlintFrame`). The game path can't be unit-tested because no test builds a `Game`, so the before/after evidence is the measurements above. With the change: `a_frame_glint_is_shared_by_every_item ... ok`. - `cargo build --profile fast -p horizon-client --bins`, single player on the server thread: - 9610 frozen drops in view: `horizon-ctl bench` and the `entity_geometry` spans as above. - An enchanted diamond sword (held and in the hotbar) and a dropped Protection IV chestplate still show the glint. The held sword's glint moves between two screenshots 0.6 s apart. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:12:19 +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#5395
No description provided.