From ed8f3d70b8528c1d5a5711303ba0ee1c635ec7f4 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Thu, 15 Oct 2026 04:06:42 +0200 Subject: [PATCH] Keep each worker's face visibility table across mesh jobs Every mesh job cloned the whole FaceVisibility (every state, every face VoxelShape and the occlusion cache) and dropped it afterwards: about half of the workers' busy time while a world loads. Each worker now keeps its copy, like vanilla's per-thread occlusion cache, and clones a new one only when the mesh tables change. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/streaming.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/crates/horizon-client/src/streaming.rs b/crates/horizon-client/src/streaming.rs index 4d9bac937..b77825b2f 100644 --- a/crates/horizon-client/src/streaming.rs +++ b/crates/horizon-client/src/streaming.rs @@ -10,6 +10,7 @@ use crate::{ world::World, }; use horizon_core::biome::BiomeZoom; +use horizon_world::block_render::FaceVisibility; use horizon_world::worldgen::decoration_order::DecorationOrder; use std::{ collections::{BinaryHeap, HashSet}, @@ -182,6 +183,10 @@ impl Streaming { .name(format!("horizon-worker-{i}")) .spawn(move || { let mut worker = generator.worker(); + // The face visibility table and its occlusion cache stay with + // the worker across mesh jobs, like vanilla's per-thread cache: + // cloning it per job copied every state and face shape. + let mut faces: Option<(Arc, FaceVisibility)> = None; loop { let job = { let mut queue = shared.queue.lock().unwrap(); @@ -210,6 +215,14 @@ impl Streaming { } Job::Mesh(x, sy, z, region, seq, settings) => { let context = shared.context.read().unwrap().clone(); + let visibility = match faces.take() { + Some((tables, visibility)) + if Arc::ptr_eq(&tables, &context.tables) => + { + visibility + } + _ => context.tables.visibility.clone(), + }; let mut mesher = Mesher { nether_shading: settings.nether, zoom: settings.zoom, @@ -219,9 +232,11 @@ impl Streaming { assets: &context.assets, tables: &context.tables, biomes: &context.biomes, - visibility: context.tables.visibility.clone(), + visibility, }; - Done::Meshed(x, sy, z, mesher.mesh(&borrow(®ion), sy), seq) + let mesh = mesher.mesh(&borrow(®ion), sy); + faces = Some((context.tables.clone(), mesher.visibility)); + Done::Meshed(x, sy, z, mesh, seq) } }; if send.send(done).is_err() {