Compare commits

...
Author SHA1 Message Date
Ludovic Marie 1e93f0a460 Merge remote-tracking branch 'origin/perf/recipes-read-once-2' into perf/sync-data-once 2026-11-02 05:27:56 +01:00
Ludovic MarieandClaude Opus 5.5 ed5e93d659 Server data: one read when a world data preload is running
A launch with --world starts the world data preload, which ends with
sync_data; the server thread then started its own "Server data preload"
of the same data, and adopt threw one of the two away. preload_sync_data
now leaves it to a preload still running.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-02 05:08:40 +01:00
2 changed files with 16 additions and 2 deletions

No files matched your search

+7 -2
View File
@@ -111,9 +111,14 @@ impl Game<'_> {
pub(super) struct SyncPreload(std::thread::JoinHandle<std::result::Result<SyncData, String>>);
/// Start reading the server's data beside the world's preparation; `None`
/// when it is read already, or being read (`preload_world_data`).
/// when it is read already, or being read: by `sync_data` (the lock is
/// held), or soon by a world data preload still running, which ends with
/// it. A second read would be thrown away by `adopt`.
pub(super) fn preload_sync_data(root: &std::path::Path) -> Option<SyncPreload> {
if !SYNC.try_lock().is_ok_and(|sync| sync.is_none()) {
// PRELOAD before SYNC, never both: `preload_world_data` takes SYNC
// under PRELOAD.
if super::world_loading::preload_running() || !SYNC.try_lock().is_ok_and(|sync| sync.is_none())
{
return None;
}
let root = root.to_owned();
@@ -483,6 +483,15 @@ pub(super) fn preload_launch_world(
}
}
/// Whether the "World data preload" thread is still running: it reads the
/// server's data (`sync_data`) last, so nothing else needs to.
pub(super) fn preload_running() -> bool {
matches!(
&*PRELOAD.lock().unwrap_or_else(|e| e.into_inner()),
Preload::Started { thread, .. } if !thread.is_finished()
)
}
/// A world opens: what `preload_world_data` read is the world's from now on.
pub(super) fn world_data_used() {
*PRELOAD.lock().unwrap_or_else(|e| e.into_inner()) = Preload::Used;