[PR #1790] [CLOSED] PackedStorage: find an entry's word by multiply and shift, not division #3763

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/1790
Author: @ludovic111
Created: 10/25/2026
Status: ❌ Closed

Base: main ← Head: perf/packed-storage-no-div


📝 Commits (3)

  • 74fa176 PackedStorage: find an entry's word by multiply and shift, not division
  • a15f8f8 Merge main (the save_root lint fix, #1789)
  • f36a278 Merge remote-tracking branch 'origin/main' into perf/packed-storage-no-div

📊 Changes

1 file changed (+58 additions, -8 deletions)

View changed files

📝 crates/horizon-core/src/storage.rs (+58 -8)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

PackedStorage (horizon-core's bit storage: proto chunk sections and heightmaps) now finds an entry's word with a multiply and a shift instead of index / per_word and index % per_word.

Every block read and write during generation went through that division. The divisor is known only at run time, and on x86 such a division costs tens of cycles. Vanilla's SimpleBitStorage avoids it with its MAGIC table. This storage keeps the rounded-up reciprocal 2^32 / per_word + 1. The reciprocal is exact for every index below 2^26 and every word size: the overshoot stays below index / 2^32 < 1 / per_word. A test checks every word size, every index of a section, a sweep up to the limit, and the indices around it. Storages longer than the limit still divide.

Measured

ThinkPad (i5-7200U), chunkgen_bench --seed 1234 --size 10 --threads 1 --center 12 -18 --warmup, 5 runs of main and 5 of this branch, alternated. The 1-minute load was 3.0–4.1 during the runs: another session's jobs were using the other cores, and the bench uses one.

main this branch
ms per proto chunk (runs 2–5) 13.2 / 13.2 / 13.3 / 13.6 12.8 / 12.6 / 12.6 / 12.6
surface 5.09–5.34 ms 4.67–4.69 ms
biomes 0.71–0.73 ms 0.63 ms
noise 5.09–5.22 ms 5.08–5.14 ms

That is −5% per proto chunk. Proto generation is about 56% of the worker CPU while a world loads. The first run of each was cold: 19.4 vs 23.3 ms. The Mac mini A/B could not be measured, at load 60+ with 32–85 ms swings. Apple's cores divide in hardware, so it should be neutral there.

Self-check

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at 21ff80eb8, 4 min 19 s)

Check Result
Scope ✅ 1 files, +58 −8
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ (18 s)
clippy ✅ (2 min 43 s)
tests: horizon-core ✅ 113 passed (37 s)
doc tests ✅ 0 passed
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 329 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo and 317 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

Named harnesses for what the storage serves (tools/parity.py chunk_generation heightmap material_surface noise worldgen save_roundtrip feature_region decorated_region): 8 passed, 0 failed (9.1 min). An earlier full run had passed 59 of the affected harnesses with no failure before I stopped it to free the busy Mac. CI's parity job runs the rest.

🤖 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/1790 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/25/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `perf/packed-storage-no-div` --- ### 📝 Commits (3) - [`74fa176`](https://github.com/horizon-rust/horizon/commit/74fa176cc8444af86c342c15eeff89398c9dcf8e) PackedStorage: find an entry's word by multiply and shift, not division - [`a15f8f8`](https://github.com/horizon-rust/horizon/commit/a15f8f8695307cffcd5d662a29a7a3e8e75a52a0) Merge main (the save_root lint fix, #1789) - [`f36a278`](https://github.com/horizon-rust/horizon/commit/f36a278760479ea5a9507b401b48668b5ccb1647) Merge remote-tracking branch 'origin/main' into perf/packed-storage-no-div ### 📊 Changes **1 file changed** (+58 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-core/src/storage.rs` (+58 -8) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. `PackedStorage` (horizon-core's bit storage: proto chunk sections and heightmaps) now finds an entry's word with a multiply and a shift instead of `index / per_word` and `index % per_word`. Every block read and write during generation went through that division. The divisor is known only at run time, and on x86 such a division costs tens of cycles. Vanilla's `SimpleBitStorage` avoids it with its MAGIC table. This storage keeps the rounded-up reciprocal `2^32 / per_word + 1`. The reciprocal is exact for every index below 2^26 and every word size: the overshoot stays below `index / 2^32 < 1 / per_word`. A test checks every word size, every index of a section, a sweep up to the limit, and the indices around it. Storages longer than the limit still divide. ## Measured ThinkPad (i5-7200U), `chunkgen_bench --seed 1234 --size 10 --threads 1 --center 12 -18 --warmup`, 5 runs of main and 5 of this branch, alternated. The 1-minute load was 3.0–4.1 during the runs: another session's jobs were using the other cores, and the bench uses one. | | main | this branch | |---|---|---| | ms per proto chunk (runs 2–5) | 13.2 / 13.2 / 13.3 / 13.6 | 12.8 / 12.6 / 12.6 / 12.6 | | surface | 5.09–5.34 ms | 4.67–4.69 ms | | biomes | 0.71–0.73 ms | 0.63 ms | | noise | 5.09–5.22 ms | 5.08–5.14 ms | That is −5% per proto chunk. Proto generation is about 56% of the worker CPU while a world loads. The first run of each was cold: 19.4 vs 23.3 ms. The Mac mini A/B could not be measured, at load 60+ with 32–85 ms swings. Apple's cores divide in hardware, so it should be neutral there. ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at 21ff80eb8, 4 min 19 s) | Check | Result | | --- | --- | | Scope | ✅ 1 files, +58 −8 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ (18 s) | | clippy | ✅ (2 min 43 s) | | tests: horizon-core | ✅ 113 passed (37 s) | | doc tests | ✅ 0 passed | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 329 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo and 317 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | Named harnesses for what the storage serves (`tools/parity.py chunk_generation heightmap material_surface noise worldgen save_roundtrip feature_region decorated_region`): 8 passed, 0 failed (9.1 min). An earlier full run had passed 59 of the affected harnesses with no failure before I stopped it to free the busy Mac. CI's parity job runs the rest. 🤖 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 04:12:08 +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#3763
No description provided.