[PR #6260] [MERGED] Native mods: a revision on mod block entities, so kept geometry is checked in O(1) #6749

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6260
Author: @ErikKalikas
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: mod-block-entity-revision


📝 Commits (4)

  • fbe0014 Mod block entities: a revision instead of comparing kept geometry's entity
  • e18c1ab Merge remote-tracking branch 'upstream/main' into mod-block-entity-revision
  • bbb8ad3 Mod block entities: name vanilla's handleBlockEntityData for the client's merge
  • 978591e Merge remote-tracking branch 'origin/main' into fix-6260

📊 Changes

10 files changed (+267 additions, -70 deletions)

View changed files

📝 crates/horizon-client-render/src/chunk/block_entity.rs (+150 -3)
📝 crates/horizon-client-render/src/containers.rs (+3 -2)
📝 crates/horizon-client/src/game/block_edits.rs (+14 -8)
📝 crates/horizon-client/src/game/native_block_entity_draw.rs (+61 -28)
📝 crates/horizon-client/src/game/native_hooks.rs (+10 -6)
📝 crates/horizon-client/src/game/remote.rs (+4 -4)
📝 crates/horizon-client/src/lan/chunks.rs (+3 -3)
📝 crates/horizon-client/src/lan/menu.rs (+9 -6)
📝 crates/horizon-client/src/save.rs (+9 -6)
📝 crates/horizon-client/tests/lan_bot.rs (+4 -4)

📄 Description

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

What and why

Fixes #6244. Follow-up to #5707, from @levzzz5154's review there: kept geometry (draw.keep()) checked every kept mod block entity in view each frame with a deep e.entity == *entity compare of ModBlockEntity, and kept a clone of it per machine. With a real machine's update tag that is microseconds per machine, so milliseconds a frame for a big base, spent on machines that did not change.

Now the check compares two integers:

  • ModBlockEntity keeps its fields behind Deref/DerefMut (ModBlockEntityFields: id, nbt, items, data). Code reads and writes them as before (entity.nbt.insert(...)). Every mutable access counts the entity's revision() on, so no write path can skip it: the fields are private outside chunk/block_entity.rs. The same idea as Bevy's Mut<T> change detection.
  • A new or cloned entity takes a fresh revision from a global counter, so one replaced in place (its chunk sent again, its block placed again) never matches what was kept. std::mem::take in the tick moves the revision with the value.
  • KeptGeometry keeps the revision it drew at, not a clone.
  • The client merges an update tag field by field (merge_update_tag, for vanilla's handleBlockEntityData) and changes nothing when the server sends the same tag again. The hub sends one on every block-log entry (native_block_entity_sync, any block change there), so without this a resend would redraw where the old compare didn't.
  • PartialEq, Debug and the save format are the fields' alone, as before.

Mods: no new hook or helper, so no fragment. Hook code compiles unchanged unless it builds a ModBlockEntity with a struct literal or destructures it, which hooks never needed (native_block_entity gives (id, nbt)). Inside Horizon the literals became ModBlockEntityFields { .. }.into().

Related: #6039 batches static geometry of vanilla block entities into chunk sections; this revision is what such a batch would key mod block entities on.

Measured

A micro-benchmark (--profile fast, not committed) of the per-frame check, before (lookup + deep compare, as KeptGeometry::get did) and after (lookup + revision compare), 300 frames:

Kept machines Update tag Before After
4096 2 fields 0.15 ms/frame 0.04 ms/frame
4096 13 fields 1.02 ms/frame 0.04 ms/frame
4096 15 fields + 27 item compounds + 2 fluids 11.0 ms/frame 0.04 ms/frame
16384 same 40.5 ms/frame 0.21 ms/frame

About 10–13 ns per machine after, whatever the tag holds. Keeping 4096 large machines (cloning each) also went from 39 ms to 0.1 ms.

Checked in game

A test mod (temporary code, not committed): 6 machines whose progress goes up every 100 ticks and whose unchanged tag is resent every 20 ticks; native_block_entity_submit draws a column as tall as the progress and calls draw.keep(), and logs each call.

  • Single player (server thread): 7 native_block_entity_submit calls per machine in 600 ticks, one per progress value; the ~30 unchanged resends drew nothing again. The columns grew with each change.
  • Dedicated server (horizon-client --dedicated, the game joining it): the same, 7 calls per machine, one per change.

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

Horizon-only, as #5707: vanilla has no such cache (BlockEntityRenderer.submit runs each frame). The client's merge stands for ClientPacketListener.handleBlockEntityData's loadWithComponents of the sent tag, as it did; it now leaves fields that already equal the sent ones alone.

Other projects' code

none

Self-check

pr_ready (tools/pr_ready.py --quick --base upstream/main on kased-h610mkddr4, against upstream/main at 455b6916b, 1 min 42 s)

Check Result
Scope ✅ 10 files, +268 −70
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 586 passed (28 s)
rustfmt ✅ (6 s)
clippy ✅ (19 s)
tests: horizon-client, horizon-client-render ✅ 2724 passed (47 s)
doc tests ✅ 0 passed (2 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

Screenshots

Dedicated server, the same machines at the start and after 600 ticks (kept columns redrawn once per change):

изображение

🤖 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/6260 **Author:** [@ErikKalikas](https://github.com/ErikKalikas) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `mod-block-entity-revision` --- ### 📝 Commits (4) - [`fbe0014`](https://github.com/horizon-rust/horizon/commit/fbe0014279d78404f6bb030cc61e4da0db8268e0) Mod block entities: a revision instead of comparing kept geometry's entity - [`e18c1ab`](https://github.com/horizon-rust/horizon/commit/e18c1abd0704adb1d6ae02cb53d50de39c46ba10) Merge remote-tracking branch 'upstream/main' into mod-block-entity-revision - [`bbb8ad3`](https://github.com/horizon-rust/horizon/commit/bbb8ad3e13243d089ab6b18fe400615ad23cdf65) Mod block entities: name vanilla's handleBlockEntityData for the client's merge - [`978591e`](https://github.com/horizon-rust/horizon/commit/978591ea138ff4d75ad7039308bbdf3ca928ddd2) Merge remote-tracking branch 'origin/main' into fix-6260 ### 📊 Changes **10 files changed** (+267 additions, -70 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/chunk/block_entity.rs` (+150 -3) 📝 `crates/horizon-client-render/src/containers.rs` (+3 -2) 📝 `crates/horizon-client/src/game/block_edits.rs` (+14 -8) 📝 `crates/horizon-client/src/game/native_block_entity_draw.rs` (+61 -28) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+10 -6) 📝 `crates/horizon-client/src/game/remote.rs` (+4 -4) 📝 `crates/horizon-client/src/lan/chunks.rs` (+3 -3) 📝 `crates/horizon-client/src/lan/menu.rs` (+9 -6) 📝 `crates/horizon-client/src/save.rs` (+9 -6) 📝 `crates/horizon-client/tests/lan_bot.rs` (+4 -4) </details> ### 📄 Description > 🤖 Opened by ErikKalikas's AI agent (Claude Code, Claude Opus 5.5), not by ErikKalikas personally. ## What and why Fixes #6244. Follow-up to #5707, from @levzzz5154's review there: kept geometry (`draw.keep()`) checked every kept mod block entity in view each frame with a deep `e.entity == *entity` compare of `ModBlockEntity`, and kept a clone of it per machine. With a real machine's update tag that is microseconds per machine, so milliseconds a frame for a big base, spent on machines that did not change. Now the check compares two integers: - **`ModBlockEntity` keeps its fields behind `Deref`/`DerefMut`** (`ModBlockEntityFields`: `id`, `nbt`, `items`, `data`). Code reads and writes them as before (`entity.nbt.insert(...)`). Every mutable access counts the entity's `revision()` on, so no write path can skip it: the fields are private outside `chunk/block_entity.rs`. The same idea as Bevy's `Mut<T>` change detection. - **A new or cloned entity takes a fresh revision** from a global counter, so one replaced in place (its chunk sent again, its block placed again) never matches what was kept. `std::mem::take` in the tick moves the revision with the value. - **`KeptGeometry` keeps the revision it drew at**, not a clone. - **The client merges an update tag field by field** (`merge_update_tag`, for vanilla's `handleBlockEntityData`) and changes nothing when the server sends the same tag again. The hub sends one on every block-log entry (`native_block_entity_sync`, any block change there), so without this a resend would redraw where the old compare didn't. - `PartialEq`, `Debug` and the save format are the fields' alone, as before. Mods: no new hook or helper, so no fragment. Hook code compiles unchanged unless it builds a `ModBlockEntity` with a struct literal or destructures it, which hooks never needed (`native_block_entity` gives `(id, nbt)`). Inside Horizon the literals became `ModBlockEntityFields { .. }.into()`. Related: #6039 batches static geometry of vanilla block entities into chunk sections; this revision is what such a batch would key mod block entities on. ### Measured A micro-benchmark (`--profile fast`, not committed) of the per-frame check, before (lookup + deep compare, as `KeptGeometry::get` did) and after (lookup + revision compare), 300 frames: | Kept machines | Update tag | Before | After | | --- | --- | --- | --- | | 4096 | 2 fields | 0.15 ms/frame | 0.04 ms/frame | | 4096 | 13 fields | 1.02 ms/frame | 0.04 ms/frame | | 4096 | 15 fields + 27 item compounds + 2 fluids | 11.0 ms/frame | 0.04 ms/frame | | 16384 | same | 40.5 ms/frame | 0.21 ms/frame | About 10–13 ns per machine after, whatever the tag holds. Keeping 4096 large machines (cloning each) also went from 39 ms to 0.1 ms. ### Checked in game A test mod (temporary code, not committed): 6 machines whose progress goes up every 100 ticks and whose unchanged tag is resent every 20 ticks; `native_block_entity_submit` draws a column as tall as the progress and calls `draw.keep()`, and logs each call. - **Single player (server thread):** 7 `native_block_entity_submit` calls per machine in 600 ticks, one per progress value; the ~30 unchanged resends drew nothing again. The columns grew with each change. - **Dedicated server** (`horizon-client --dedicated`, the game joining it): the same, 7 calls per machine, one per change. ## 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 Horizon-only, as #5707: vanilla has no such cache (`BlockEntityRenderer.submit` runs each frame). The client's merge stands for `ClientPacketListener.handleBlockEntityData`'s `loadWithComponents` of the sent tag, as it did; it now leaves fields that already equal the sent ones alone. ## Other projects' code none ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base upstream/main` on kased-h610mkddr4, against upstream/main at 455b6916b, 1 min 42 s) | Check | Result | | --- | --- | | Scope | ✅ 10 files, +268 −70 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 586 passed (28 s) | | rustfmt | ✅ (6 s) | | clippy | ✅ (19 s) | | tests: horizon-client, horizon-client-render | ✅ 2724 passed (47 s) | | doc tests | ✅ 0 passed (2 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | ## Screenshots Dedicated server, the same machines at the start and after 600 ticks (kept columns redrawn once per change): <img width="1280" height="720" alt="изображение" src="https://github.com/user-attachments/assets/6ab0b11a-8efa-482d-bc57-9cfa6587bec9" /> 🤖 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 06:26:05 +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#6749
No description provided.