From 0c161a03364fb006db381e369556113a0b1d75cc Mon Sep 17 00:00:00 2001 From: rdbtCVS <87152661+rdbtCVS@users.noreply.github.com> Date: Thu, 15 Oct 2026 10:37:46 +0100 Subject: [PATCH] Cache random-tick section eligibility for unchanged chunks --- .../examples/random_tick_eligibility_bench.rs | 149 ++++++++ crates/horizon-client/src/game.rs | 20 +- crates/horizon-client/src/game/packs.rs | 1 + crates/horizon-client/src/lib.rs | 1 + .../src/random_tick_sections.rs | 353 ++++++++++++++++++ docs/random-tick-eligibility-benchmark.md | 66 ++++ 6 files changed, 577 insertions(+), 13 deletions(-) create mode 100644 crates/horizon-client/examples/random_tick_eligibility_bench.rs create mode 100644 crates/horizon-client/src/random_tick_sections.rs create mode 100644 docs/random-tick-eligibility-benchmark.md diff --git a/crates/horizon-client/examples/random_tick_eligibility_bench.rs b/crates/horizon-client/examples/random_tick_eligibility_bench.rs new file mode 100644 index 000000000..856d7d520 --- /dev/null +++ b/crates/horizon-client/examples/random_tick_eligibility_bench.rs @@ -0,0 +1,149 @@ +//! Selection cost only (not block simulation). Run with prepared client resources. +//! cargo run --profile fast -p horizon-client --example random_tick_eligibility_bench -- RESOURCES +use horizon_client::{ + blocks::BlockFacts, + chunk::{Chunk, MIN_Y, Section}, + fast_hash::FxHashMap, + random_tick_sections::RandomTickSections, +}; +use horizon_world::registry::BlockStateId; +use std::{hint::black_box, path::Path, sync::Arc, time::Instant}; + +fn select_baseline(chunks: &FxHashMap<(i32, i32), Arc>, facts: &BlockFacts) -> usize { + let mut ticking = Vec::new(); + for (&(x, z), chunk) in chunks { + if x.abs() > 8 || z.abs() > 8 || !chunk.lit { + continue; + } + let sections: Vec = chunk + .sections + .iter() + .enumerate() + .filter(|(_, s)| { + s.blocks + .maybe_has(|id| facts.get(BlockStateId(id)).random_ticks) + }) + .map(|(i, _)| MIN_Y + i as i32 * 16) + .collect(); + ticking.push((x, z, sections)); + } + black_box(ticking).iter().map(|(_, _, s)| s.len()).sum() +} + +fn select_cached( + chunks: &FxHashMap<(i32, i32), Arc>, + facts: &BlockFacts, + cache: &mut RandomTickSections, +) -> usize { + let mut ticking = Vec::new(); + for (&(x, z), chunk) in chunks { + if x.abs() > 8 || z.abs() > 8 || !chunk.lit { + continue; + } + ticking.push((x, z, cache.get((x, z), chunk, facts))); + } + black_box(ticking).iter().map(|(_, _, s)| s.len()).sum() +} + +fn main() -> horizon_client::Result<()> { + let root = std::env::args() + .nth(1) + .ok_or("expected prepared client resource directory")?; + let start = Instant::now(); + let registry = horizon_world::level::data::load_registry(Path::new(&root))?; + let facts = BlockFacts::load(Path::new(&root), ®istry)?; + println!( + "resource_load_ms={:.3}", + start.elapsed().as_secs_f64() * 1000.0 + ); + let inactive: Vec = facts + .states + .iter() + .enumerate() + .filter(|(_, f)| !f.random_ticks) + .take(128) + .map(|(i, _)| i as u16) + .collect(); + let active = registry.default_state("minecraft:grass_block").unwrap().0 as u16; + assert!(facts.get(BlockStateId(u32::from(active))).random_ticks); + for (name, palette) in [("sparse", 1), ("dense", 128)] { + let start = Instant::now(); + let mut chunks = FxHashMap::default(); + for z in -8..=8 { + for x in -8..=8 { + let mut chunk = Chunk::empty(x, z); + chunk.lit = true; + for (i, section) in chunk.sections.iter_mut().enumerate() { + let mut values = std::array::from_fn(|j| inactive[j % palette]); + if i % 3 == 0 { + values[4095] = active; + } + Arc::make_mut(section).blocks = Section::from_blocks(&values); + } + chunks.insert((x, z), Arc::new(chunk)); + } + } + println!( + "{name} fixture_ms={:.3}", + start.elapsed().as_secs_f64() * 1000.0 + ); + for (workload, changed) in [ + ("steady", 0), + ("cold", 0), + ("reload", 0), + ("edit_1pct", 3), + ("edit_all", 289), + ] { + let keys: Vec<_> = chunks.keys().copied().collect(); + let mut baseline = Vec::new(); + let mut candidate = Vec::new(); + let mut cache = RandomTickSections::default(); + for sample in 0..8 { + // Alternate order; first pair warms both paths and is discarded. + for cached in if sample % 2 == 0 { + [false, true] + } else { + [true, false] + } { + let start = Instant::now(); + for tick in 0..300 { + if cached && workload == "cold" { + cache = RandomTickSections::default(); + } + if cached && workload == "reload" { + cache.clear(); + } + for key in keys.iter().take(changed) { + Arc::make_mut(chunks.get_mut(key).unwrap()).set( + 0, + MIN_Y, + 0, + inactive[tick % 2], + ); + } + black_box(if cached { + select_cached(&chunks, &facts, &mut cache) + } else { + select_baseline(&chunks, &facts) + }); + } + // Include teardown, and remove weak handles before baseline edits. + if cached { + cache = RandomTickSections::default(); + } + if sample > 0 { + let us = start.elapsed().as_secs_f64() * 1e6 / 300.0; + if cached { + candidate.push(us); + } else { + baseline.push(us); + } + } + } + } + println!("{name} {workload} baseline_us={baseline:.3?} candidate_us={candidate:.3?}"); + } + } + println!("chunk_wrapper_bytes={}", std::mem::size_of::()); + Ok(()) +} diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index f87d974e0..f56b41a3f 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -838,6 +838,7 @@ struct Game<'a> { end: end::EndState, block_ticks: Ticks, tick_chunks: HashSet<(i32, i32)>, + random_tick_sections: horizon_client::random_tick_sections::RandomTickSections, level_events: Vec, falling: Vec, paintings: Vec, @@ -1554,6 +1555,7 @@ impl Game<'_> { self.register_chunk_ticks(*k); } for k in self.tick_chunks.difference(&loaded) { + self.random_tick_sections.remove(k); self.block_ticks .remove_chunk(horizon_core::position::ChunkPos::new(k.0, k.1)); } @@ -1577,19 +1579,10 @@ impl Game<'_> { if (x - pcx).abs() > simulation || (z - pcz).abs() > simulation || !chunk.lit { continue; } - // LevelChunkSection.isRandomlyTicking: a randomly ticking block or - // fluid state (lava reports both through LiquidBlock). The palette - // stands in for vanilla's exact counts. - let sections: Vec = chunk - .sections - .iter() - .enumerate() - .filter(|(_, s)| { - s.blocks - .maybe_has(|id| facts.get(BlockStateId(id)).random_ticks) - }) - .map(|(i, _)| MIN_Y + i as i32 * 16) - .collect(); + // Capture eligibility before inside-block and scheduled updates, as + // before. Keep the world map's chunk order, including empty chunks + // (tick_chunk_random still draws for precipitation in those). + let sections = self.random_tick_sections.get((x, z), chunk, facts); ticking.push((x, z, sections)); } // Entity.checkInsideBlocks for the plates, tripwires and detector rails @@ -9344,6 +9337,7 @@ pub fn run() -> Result<()> { end: Default::default(), block_ticks: Ticks::new(0), tick_chunks: HashSet::new(), + random_tick_sections: Default::default(), level_events: Vec::new(), falling: Vec::new(), paintings: Vec::new(), diff --git a/crates/horizon-client/src/game/packs.rs b/crates/horizon-client/src/game/packs.rs index 0d3f8a74a..b2327c55c 100644 --- a/crates/horizon-client/src/game/packs.rs +++ b/crates/horizon-client/src/game/packs.rs @@ -123,6 +123,7 @@ impl Game<'_> { visibility, )?); // Everything loaded: switch over. + self.random_tick_sections.clear(); self.options.resources = root.to_path_buf(); let context = std::sync::Arc::new(horizon_client::streaming::WorkerContext { assets: assets.clone(), diff --git a/crates/horizon-client/src/lib.rs b/crates/horizon-client/src/lib.rs index 07ba1af2a..0ee40f42b 100644 --- a/crates/horizon-client/src/lib.rs +++ b/crates/horizon-client/src/lib.rs @@ -117,6 +117,7 @@ pub mod post; pub mod projectiles; pub mod raid; pub mod random_sequences; +pub mod random_tick_sections; pub mod recipe_book; pub mod recipe_book_screen; pub mod reconnect; diff --git a/crates/horizon-client/src/random_tick_sections.rs b/crates/horizon-client/src/random_tick_sections.rs new file mode 100644 index 000000000..d455c9e77 --- /dev/null +++ b/crates/horizon-client/src/random_tick_sections.rs @@ -0,0 +1,353 @@ +//! Memoized palette eligibility for the game thread's random-tick snapshot. +use crate::{ + blocks::BlockFacts, + chunk::{Chunk, MIN_Y, SECTIONS}, + fast_hash::FxHashMap, +}; +use horizon_world::registry::BlockStateId; +use std::sync::{Arc, Weak}; + +/// A value snapshot, in ascending section order, with no per-chunk allocation. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +pub struct Sections(u32); +impl Iterator for Sections { + type Item = i32; + fn next(&mut self) -> Option { + if self.0 == 0 { + return None; + } + let index = self.0.trailing_zeros(); + self.0 &= self.0 - 1; + Some(MIN_Y + index as i32 * 16) + } + fn size_hint(&self) -> (usize, Option) { + let len = self.0.count_ones() as usize; + (len, Some(len)) + } +} +impl ExactSizeIterator for Sections {} + +struct Cached { + chunk: Weak, + sections: Sections, +} +/// Resident chunks are immutable behind `Arc`; edits use `Arc::make_mut`. +/// A weak reference detects both edits and replacement, without retaining block +/// data or forcing a deep copy on the next edit. It also prevents address reuse. +/// Clear this cache whenever the gameplay facts change (including resource reload). +#[derive(Default)] +pub struct RandomTickSections { + chunks: FxHashMap<(i32, i32), Cached>, +} +impl RandomTickSections { + pub fn clear(&mut self) { + self.chunks.clear(); + } + pub fn remove(&mut self, key: &(i32, i32)) { + self.chunks.remove(key); + } + pub fn get(&mut self, key: (i32, i32), chunk: &Arc, facts: &BlockFacts) -> Sections { + self.get_with(key, chunk, |id| facts.get(BlockStateId(id)).random_ticks) + } + fn get_with( + &mut self, + key: (i32, i32), + chunk: &Arc, + mut random: impl FnMut(u32) -> bool, + ) -> Sections { + const { + assert!(SECTIONS <= u32::BITS as usize); + } + let cached = self.chunks.entry(key).or_insert_with(|| Cached { + chunk: Weak::new(), + sections: Sections::default(), + }); + if cached.chunk.as_ptr() != Arc::as_ptr(chunk) { + let mut mask = 0; + for (i, section) in chunk.sections.iter().enumerate() { + // Preserve maybe_has, including unused entries and global palettes. + if section.blocks.maybe_has(&mut random) { + mask |= 1 << i; + } + } + cached.sections = Sections(mask); + cached.chunk = Arc::downgrade(chunk); + } + cached.sections + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::chunk::Section; + + #[test] + fn edits_replacements_compaction_and_reload() { + let mut cache = RandomTickSections::default(); + let mut chunk = Arc::new(Chunk::empty(0, 0)); + assert_eq!(cache.get_with((0, 0), &chunk, |id| id == 1).len(), 0); + cache.get_with((0, 0), &chunk, |_| panic!("unchanged chunk rescanned")); + let worker = chunk.clone(); + Arc::make_mut(&mut chunk).set(0, MIN_Y, 0, 1); + assert_eq!( + cache + .get_with((0, 0), &chunk, |id| id == 1) + .collect::>(), + [MIN_Y] + ); + assert_eq!(worker.get(0, MIN_Y, 0), 0); + // Even after the last ticking block is removed, its unused palette entry counts. + Arc::make_mut(&mut chunk).set(0, MIN_Y, 0, 0); + assert_eq!(cache.get_with((0, 0), &chunk, |id| id == 1).len(), 1); + Arc::make_mut(&mut Arc::make_mut(&mut chunk).sections[0]).compact(); + assert_eq!(cache.get_with((0, 0), &chunk, |id| id == 1).len(), 0); + Arc::make_mut(&mut chunk).sections[SECTIONS - 1] = Arc::new(Section::default()); + cache.clear(); // resource reload, with changed facts for the same state IDs + assert_eq!(cache.get_with((0, 0), &chunk, |id| id == 0).len(), SECTIONS); + cache.remove(&(0, 0)); + assert!(cache.chunks.is_empty()); + } + + #[test] + fn replacement_at_same_coordinates_and_early_snapshot() { + let mut cache = RandomTickSections::default(); + let mut chunk = Arc::new(Chunk::empty(-2, 3)); + let before_scheduled = cache.get_with((-2, 3), &chunk, |id| id == 1); + Arc::make_mut(&mut chunk).set(0, MIN_Y + 16, 0, 1); + assert_eq!(before_scheduled.len(), 0); + assert_eq!( + cache + .get_with((-2, 3), &chunk, |id| id == 1) + .collect::>(), + [MIN_Y + 16] + ); + let weak = Arc::downgrade(&chunk); + drop(chunk); + assert!(weak.upgrade().is_none()); // cache does not retain unloaded block data + let replacement = Arc::new(Chunk::empty(-2, 3)); + assert_eq!(cache.get_with((-2, 3), &replacement, |id| id == 1).len(), 0); + } + + #[test] + fn global_palette_and_ascending_order() { + let mut chunk = Chunk::empty(0, 0); + for i in [0, 9, SECTIONS - 1] { + Arc::make_mut(&mut chunk.sections[i]).blocks = + Section::from_blocks(&std::array::from_fn(|j| (j % 300) as u16)); + } + let chunk = Arc::new(chunk); + let mut cache = RandomTickSections::default(); + // Global maybe_has considers the entire ID range, including absent states. + assert_eq!( + cache + .get_with((0, 0), &chunk, |id| id == 40000) + .collect::>(), + [MIN_Y, MIN_Y + 9 * 16, MIN_Y + (SECTIONS as i32 - 1) * 16] + ); + } +} + +#[cfg(test)] +mod tick_parity { + use super::*; + use horizon_core::{ + position::{BlockPos, ChunkPos}, + random::{LegacyRandom, RandomSource}, + }; + use horizon_world::level::{Behaviours, LevelAccess, LevelEvent, Ticks, data}; + use std::{cell::RefCell, path::PathBuf}; + + #[derive(Clone)] + struct Level { + chunks: FxHashMap<(i32, i32), Arc>, + random: LegacyRandom, + reads: RefCell>, + events: Vec, + time: i64, + speed: i32, + } + impl LevelAccess for Level { + fn block_state(&self, pos: BlockPos) -> BlockStateId { + self.reads.borrow_mut().push(pos); + self.chunks + .get(&(pos.x >> 4, pos.z >> 4)) + .map_or(BlockStateId(0), |c| c.block(pos.x, pos.y, pos.z)) + } + fn set_raw(&mut self, pos: BlockPos, state: BlockStateId) -> Option { + let chunk = self.chunks.get_mut(&(pos.x >> 4, pos.z >> 4))?; + Some(BlockStateId(u32::from(Arc::make_mut(chunk).set( + pos.x, + pos.y, + pos.z, + state.0 as u16, + )))) + } + fn is_loaded(&self, pos: BlockPos) -> bool { + self.chunks.contains_key(&(pos.x >> 4, pos.z >> 4)) + } + fn random(&mut self) -> &mut LegacyRandom { + &mut self.random + } + fn game_time(&self) -> i64 { + self.time + } + fn game_rules(&self) -> horizon_world::level::GameRules { + horizon_world::level::GameRules { + random_tick_speed: self.speed, + ..Default::default() + } + } + fn emit(&mut self, event: LevelEvent) { + self.events.push(event); + } + } + + #[test] + fn actual_random_ticks_match_original_scan() { + let root = std::env::var_os("HORIZON_RESOURCES") + .map(PathBuf::from) + .unwrap_or_else(|| { + PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3") + }); + if !root.join("gameplay-facts.json").exists() { + eprintln!( + "skipping resource-backed random-tick parity: {}", + root.display() + ); + return; + } + let registry = data::load_registry(&root).unwrap(); + let mut facts = BlockFacts::load(&root, ®istry).unwrap(); + let behaviours = Behaviours::load(®istry, &root).unwrap(); + let grass = registry.default_state("minecraft:grass_block").unwrap(); + let chunk = |x| { + let mut c = Chunk::empty(x, 0); + c.lit = true; + // Every sampled block can run real behaviour and change to dirt. + for i in [4, 7] { + Arc::make_mut(&mut c.sections[i]).blocks = + crate::chunk::Section::from_blocks(&[grass.0 as u16; 4096]); + } + Arc::new(c) + }; + let mut original = Level { + chunks: [ + ((-1, 0), chunk(-1)), + ((0, 0), chunk(0)), + ((1, 0), Arc::new(Chunk::empty(1, 0))), + ] + .into_iter() + .collect(), + random: LegacyRandom::new(42), + reads: RefCell::default(), + events: Vec::new(), + time: 0, + speed: 3, + }; + Arc::make_mut(original.chunks.get_mut(&(1, 0)).unwrap()).lit = true; // precipitation-only chunk + let mut cached = original.clone(); + let mut cache = RandomTickSections::default(); + let (mut a, mut b) = (Ticks::new(12345), Ticks::new(12345)); + for x in -1..=1 { + a.add_empty_chunk(ChunkPos::new(x, 0)).unwrap(); + b.add_empty_chunk(ChunkPos::new(x, 0)).unwrap(); + } + for step in 0..128 { + for level in [&mut original, &mut cached] { + level.time = step; + level.speed = [0, 1, 3, 9][step as usize % 4]; + level.reads.borrow_mut().clear(); + level.events.clear(); + match step { + 12 => { + level.chunks.remove(&(-1, 0)); + } + 13 => { + level.chunks.insert((-1, 0), chunk(-1)); + } + 30 => { + Arc::make_mut(level.chunks.get_mut(&(0, 0)).unwrap()).sections[7] = + Arc::new(crate::chunk::Section::default()); + } + 40 | 41 => { + Arc::make_mut(level.chunks.get_mut(&(0, 0)).unwrap()).lit = step == 41; + } + _ => {} + } + } + if step == 12 { + cache.remove(&(-1, 0)); + } + if step == 50 || step == 60 { + facts.states[grass.0 as usize].random_ticks = step == 60; + cache.clear(); + } + let old: Vec<_> = original + .chunks + .iter() + .filter(|(_, c)| c.lit) + .map(|(&key, c)| { + let sections: Vec<_> = c + .sections + .iter() + .enumerate() + .filter(|(_, s)| { + s.blocks + .maybe_has(|id| facts.get(BlockStateId(id)).random_ticks) + }) + .map(|(i, _)| MIN_Y + i as i32 * 16) + .collect(); + (key, sections) + }) + .collect(); + let new: Vec<_> = cached + .chunks + .iter() + .filter(|(_, c)| c.lit) + .map(|(&key, c)| (key, cache.get(key, c, &facts))) + .collect(); + assert_eq!( + old, + new.iter() + .map(|(k, s)| (*k, s.collect::>())) + .collect::>() + ); + // Stand in for an inside-block/scheduled write AFTER eligibility capture. + if step == 20 { + for level in [&mut original, &mut cached] { + level.set_raw(BlockPos::new(0, MIN_Y + 16, 0), grass); + } + } + for ((x, z), sections) in old { + behaviours.tick_chunk_random(&mut original, &mut a, ChunkPos::new(x, z), sections); + } + for ((x, z), sections) in new { + behaviours.tick_chunk_random(&mut cached, &mut b, ChunkPos::new(x, z), sections); + } + assert_eq!(original.reads, cached.reads, "ordered reads at tick {step}"); + assert_eq!(original.events, cached.events, "events at tick {step}"); + assert_eq!( + a.random_tick_value, b.random_tick_value, + "position RNG at tick {step}" + ); + assert_eq!( + original.random.next_long(), + cached.random.next_long(), + "level RNG at tick {step}" + ); + } + let dirt = registry.default_state("minecraft:dirt").unwrap(); + assert!( + original + .chunks + .values() + .any(|c| c.sections[4].blocks.maybe_has(|id| id == dirt.0)) + ); + for (key, c) in &original.chunks { + for (s, t) in c.sections.iter().zip(&cached.chunks[key].sections) { + assert_eq!(s.blocks, t.blocks); + } + } + } +} diff --git a/docs/random-tick-eligibility-benchmark.md b/docs/random-tick-eligibility-benchmark.md new file mode 100644 index 000000000..9a1e46516 --- /dev/null +++ b/docs/random-tick-eligibility-benchmark.md @@ -0,0 +1,66 @@ +# Random-tick eligibility benchmark + +Run with the pinned prepared client resources: + +```sh +flock /tmp/horizon-optimizations-20261015-heavy.lock env CARGO_BUILD_JOBS=2 \ + CARGO_TARGET_DIR=/home/bob/Documents/horizon/target \ + cargo run --profile fast -p horizon-client --example random_tick_eligibility_bench -- \ + .local/horizon-client/26.3 +``` + +The example keeps the original selection algorithm alongside the cache. Both run +in the same optimized binary, alternating measurement order. Each workload has +one discarded warmup pair and seven pairs of 300 ticks. It reports every sample, +resource loading and fixture construction separately. This measures eligibility +selection and writes, not whole-game tick latency or rendering. + +There are 289 lit chunks (simulation distance eight), each with 24 sections. +Sparse sections have one non-ticking state; dense sections have 128 distinct +non-ticking states selected from the real prepared facts. Every third section +also contains grass at its final position. These are controlled fixtures, not a +claim about typical generated terrain. + +Steady includes initial cache fill amortized over 300 ticks. Cold recreates the +cache each tick, including allocation and destruction; reload clears it each +tick while retaining capacity. Edit workloads alternate a block value in three +or all 289 chunks before every selection. Timing includes the additional +`Arc::make_mut` allocation caused by weak cache handles; the baseline drops those +handles before its turn. Both paths retain the original outer-vector allocation. + +The initial scan-only baseline was measured before implementing the cache with +the same fast profile: sparse steady median 49.277 us and dense steady median +1487.781 us. Paired results below are the comparison used for the keep decision. + +Measured on an AMD Ryzen 5 5600X (12 logical CPUs), Linux x86-64, rustc +1.99.0 (b940084d7), using `fast` (release optimization, LTO off, 16 codegen units). +All build/measurement commands held the shared heavy-work lock with two build +jobs. Resource loading took 1086 ms; fixture construction took 85 ms sparse and +375 ms dense, shared by both implementations. + +Median microseconds per tick (seven paired samples): + +| Palette | Workload | Original | Cached | Speedup | +| --- | --- | ---: | ---: | ---: | +| sparse | steady | 48.855 | 2.588 | 18.88x | +| sparse | cold | 50.319 | 39.110 | 1.29x | +| sparse | reload | 49.051 | 36.167 | 1.36x | +| sparse | edit_1pct | 49.110 | 2.850 | 17.23x | +| sparse | edit_all | 59.425 | 50.759 | 1.17x | +| dense | steady | 1311.924 | 4.397 | 298.37x | +| dense | cold | 1305.237 | 553.209 | 2.36x | +| dense | reload | 1292.879 | 542.848 | 2.38x | +| dense | edit_1pct | 1290.162 | 9.102 | 141.74x | +| dense | edit_all | 1303.115 | 561.606 | 2.32x | + +Keep: steady selection improves repeatedly, and cold/refill/edit-heavy selection +also improves in this fixture. No whole-game speedup is inferred from this +microbenchmark. Real terrain's palette sizes and block-write frequency determine +the gain. Lighting and other chunk changes conservatively invalidate eligibility. + +The cache adds a weak handle and mask per cached resident chunk: about 13 KiB of +hash-table storage for 289 entries on this platform, including capacity slack. +It retains no unloaded block data. A first edit after caching can allocate/move +the 176-byte chunk wrapper (plus Arc bookkeeping); it does not force a deep +copy. The edit rows include this cost. Unloads remove entries; resource reload +clears the cache. The original outer tick-vector allocation remains.