Paletted container access: skip the storage revalidation a section already did
BlockSection::get and set check the section index and the state id once, then read and write through new PackedStorage::read/write, which skip the storage-level bounds and value checks and the Result that get/set keep for external callers. A section index is below 4,096 and a palette id always fits the width bits_for_palette chose; both methods debug_assert that contract. Used for the hot read, the hot write and the growth re-encode. Benchmark (ignored tests, best of alternating-order rounds, fast profile): BlockSection::set 13.15 -> 9.12 ns/write (1.44x), get 2.33 -> 1.45 ns/read (1.61x). See docs/performance/paletted-container-access-results.md.
This commit is contained in:
@@ -5,8 +5,9 @@ chunk workers: light and mesh workers unpack a section's 4,096 cells before
|
||||
propagating or meshing, and world-generation workers write one block at a time
|
||||
through `BlockSection::set`.
|
||||
|
||||
Two redundant lookups were removed from the write path, and the palette dispatch
|
||||
was hoisted in the bulk readers.
|
||||
The write path resolved the old cell and probed the palette three times; the
|
||||
bulk readers dispatched the palette per cell; and the storage layer revalidated
|
||||
indices and values a section had already checked. All three are addressed.
|
||||
|
||||
## Changes
|
||||
|
||||
@@ -19,6 +20,14 @@ now read straight from storage, and the incoming state is resolved with a single
|
||||
map probe. The palette-reuse, free-slot and growth paths are unchanged, so the
|
||||
encoded palette, counts, free list and NBT output stay identical.
|
||||
|
||||
`BlockSection::get` and `set` validate the section index and the state id once,
|
||||
then read and write through `PackedStorage::read`/`write`
|
||||
(`crates/horizon-core/src/storage.rs`). These skip the storage-level bounds and
|
||||
value checks and the `Result` that `PackedStorage::get`/`set` keep for external
|
||||
callers: a section index is below 4,096 and a palette id always fits the width
|
||||
`bits_for_palette` chose. Both new methods `debug_assert` their contract and are
|
||||
used for the hot read, the hot write and the palette-growth re-encode.
|
||||
|
||||
`PalettedContainer::unpack` and `unpack_u16`
|
||||
(`crates/horizon-core/src/paletted.rs`) matched on the palette variant inside the
|
||||
per-cell loop. `Single`, `List` and `Global` are now dispatched once before the
|
||||
@@ -40,19 +49,21 @@ and NBT before timing. Rounds alternate baseline/optimized order with `black_box
|
||||
and report the median and best nanosecond- or microsecond-per-operation; the best
|
||||
round is the estimate of uninterrupted CPU time on a contended machine.
|
||||
|
||||
`benchmark_section_get_set` uses a 32-state registry and 50,000 random writes per
|
||||
round over a section whose palette grows through the 4- and 5-bit widths (24
|
||||
distinct states); 51 rounds. `benchmark_unpack` fills a 4,096-entry list palette
|
||||
(12 states) and the global palette, 2,000 calls per round, 25 rounds.
|
||||
`benchmark_section_get_set` uses a 32-state registry and 50,000 random writes and
|
||||
reads per round over a section whose palette grows through the 4- and 5-bit
|
||||
widths (24 distinct states); 51 rounds. `benchmark_unpack` fills a 4,096-entry
|
||||
list palette (12 states) and the global palette, 2,000 calls per round, 25
|
||||
rounds.
|
||||
|
||||
AMD Ryzen 5 5600X, Linux x86_64, rustc 1.99.0, optimized `fast` profile,
|
||||
nonincremental, no LTO:
|
||||
|
||||
| Operation | Original main | New | Speedup |
|
||||
| --- | ---: | ---: | ---: |
|
||||
| `BlockSection::set` | 12.73 ns/write | 11.37 ns/write | 1.12x |
|
||||
| `unpack`, list palette | 1.956 us/call | 1.860 us/call | 1.05x |
|
||||
| `unpack`, global palette | 2.255 us/call | 2.172 us/call | 1.04x |
|
||||
| `BlockSection::set` | 13.15 ns/write | 9.12 ns/write | 1.44x |
|
||||
| `BlockSection::get` | 2.33 ns/read | 1.45 ns/read | 1.61x |
|
||||
| `unpack`, list palette | 1.910 us/call | 1.834 us/call | 1.04x |
|
||||
| `unpack`, global palette | 2.270 us/call | 2.179 us/call | 1.04x |
|
||||
|
||||
The distinct-state differential test
|
||||
`chunk::tests::set_matches_baseline_under_random_edits` drives the optimized
|
||||
|
||||
Reference in New Issue
Block a user