From b18261cc799a5686349515f17ac23457fa488537 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Thu, 15 Oct 2026 09:36:11 +0200 Subject: [PATCH] Autosave doesn't wait for the entity writes The autosave queued its chunks without waiting (#284), then saved the entities with the waiting call. The region writer is one FIFO thread, so the main thread still waited for every chunk queued before the entities: a 1.9 s frame at the 5-minute autosave on a world with ~900 columns. Like PersistentEntitySectionManager.autoSave (saveAll's flush only on save-all and quit), the autosave now queues the entities too. Part of #224 Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game.rs | 2 +- crates/horizon-client/src/game/persist.rs | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 3d0dc2bb9..b406c5766 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -7957,7 +7957,7 @@ impl Game<'_> { if wait { self.save.flush(); } - self.save_entities()?; + self.save_entities(wait)?; self.save_maps(); self.save_random_sequences(); self.save_raids(); diff --git a/crates/horizon-client/src/game/persist.rs b/crates/horizon-client/src/game/persist.rs index d7bb6d558..054f2c2fc 100644 --- a/crates/horizon-client/src/game/persist.rs +++ b/crates/horizon-client/src/game/persist.rs @@ -830,7 +830,10 @@ impl Game<'_> { out.into_iter().collect() } /// Write the entities of every resident chunk (an autosave or quit). - pub(super) fn save_entities(&mut self) -> Result<()> { + /// Without `wait` (the autosave) they are written on the region writer + /// meanwhile: `PersistentEntitySectionManager.autoSave` stores them + /// without `saveAll`'s flush. + pub(super) fn save_entities(&mut self, wait: bool) -> Result<()> { self.spawn_loaded_entities(); let keys: HashSet<(i32, i32)> = self.world.chunks.keys().copied().collect(); let chunks = self.entity_chunks(&keys, false); @@ -849,7 +852,11 @@ impl Game<'_> { .collect(); self.persist.uuids.retain(|id, _| alive.contains(id)); self.persist.raw.retain(|id, _| alive.contains(id)); - self.save.save_entities(chunks) + if wait { + self.save.save_entities(chunks) + } else { + self.save.save_entities_later(chunks) + } } /// Save and remove the entities of chunks that unloaded. pub(super) fn unload_entities(&mut self, unloaded: &[Arc]) {