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 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-15 04:06:42 +02:00
parent ff5df6aa5e
commit ed8f3d70b8
+17 -2
View File
@@ -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<MeshTables>, 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(&region), sy), seq)
let mesh = mesher.mesh(&borrow(&region), sy);
faces = Some((context.tables.clone(), mesher.visibility));
Done::Meshed(x, sy, z, mesh, seq)
}
};
if send.send(done).is_err() {