[GH-ISSUE #6244] Native mods: a revision on mod block entities, so kept geometry isn't compared in full each frame #2029

Closed
opened 2026-11-02 15:51:29 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @ErikKalikas on GitHub (Nov 1, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6244

Originally assigned to: @ErikKalikas on GitHub.

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

Part of #4953, follow-up to #5707 (named in levzzz5154's review there). Kept geometry (draw.keep(), KeptGeometry in game/native_block_entity_draw.rs) checks every frame, for every kept mod block entity in view, that the entity hasn't changed with a deep e.entity == *entity compare of ModBlockEntity (id, nbt, items, data), and keeps a clone of it per machine. With a machine's update tag holding a dozen fields and an inventory, that compare costs microseconds per machine: milliseconds a frame for a base of a few thousand machines, spent on machines that did not change.

Proposal

A revision on ModBlockEntity, so the check is one comparison of two integers:

  • ModBlockEntity keeps its fields (id, nbt, items, data) behind Deref/DerefMut. Reading and writing them reads as before (entity.nbt.insert(...)), and every mutable access counts the revision on, so no write path can be missed.
  • A new or cloned entity takes a fresh revision (a global counter), so one replaced in place (the chunk reloaded, the block placed again) never matches what was kept.
  • KeptGeometry keeps the revision it drew at instead of a clone of the entity.
  • The client merges an update tag field by field and leaves the entity alone when the server sends the same tag again (the hub sends one on every block-log entry), so a resend does not redraw.
  • Equality, Debug and the save format stay the fields' alone.

Mods see no new hook or helper. Their code keeps compiling unless it builds a ModBlockEntity with a struct literal or destructures it, which the hooks never needed (native_block_entity returns (id, nbt)).

Horizon-only, as #5707: vanilla has no such cache.

Originally created by @ErikKalikas on GitHub (Nov 1, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6244 Originally assigned to: @ErikKalikas on GitHub. > 🤖 Filed by ErikKalikas's AI agent (Claude Code, Claude Opus 5.5), not by ErikKalikas personally. Part of #4953, follow-up to #5707 (named in levzzz5154's review there). Kept geometry (`draw.keep()`, `KeptGeometry` in `game/native_block_entity_draw.rs`) checks every frame, for every kept mod block entity in view, that the entity hasn't changed with a deep `e.entity == *entity` compare of `ModBlockEntity` (id, `nbt`, items, data), and keeps a clone of it per machine. With a machine's update tag holding a dozen fields and an inventory, that compare costs microseconds per machine: milliseconds a frame for a base of a few thousand machines, spent on machines that did not change. ## Proposal A revision on `ModBlockEntity`, so the check is one comparison of two integers: - `ModBlockEntity` keeps its fields (`id`, `nbt`, `items`, `data`) behind `Deref`/`DerefMut`. Reading and writing them reads as before (`entity.nbt.insert(...)`), and every mutable access counts the revision on, so no write path can be missed. - A new or cloned entity takes a fresh revision (a global counter), so one replaced in place (the chunk reloaded, the block placed again) never matches what was kept. - `KeptGeometry` keeps the revision it drew at instead of a clone of the entity. - The client merges an update tag field by field and leaves the entity alone when the server sends the same tag again (the hub sends one on every block-log entry), so a resend does not redraw. - Equality, `Debug` and the save format stay the fields' alone. Mods see no new hook or helper. Their code keeps compiling unless it builds a `ModBlockEntity` with a struct literal or destructures it, which the hooks never needed (`native_block_entity` returns `(id, nbt)`). Horizon-only, as #5707: vanilla has no such cache.
Author
Owner

@ErikKalikas commented on GitHub (Nov 1, 2026):

🤖 Agent: /claim

<!-- gh-comment-id:6562033548 --> @ErikKalikas commented on GitHub (Nov 1, 2026): 🤖 Agent: /claim
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#2029
No description provided.