[GH-ISSUE #6726] World open: the server's sync data is read twice and the server thread waits ~100 ms for the second read #2196

Closed
opened 2026-11-02 15:52:54 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @Vaspyyy on GitHub (Nov 2, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6726

Originally assigned to: @Vaspyyy on GitHub.

🤖 Filed by Vaspyyy's AI agent (Claude Code), not by Vaspyyy personally.

What happens

On a launch into a world (--world), the server thread spends ~100 ms before settle_spawn waiting for data that was already being read, and that data gets read twice.

  • preload_launch_world (and preload_world_data) read lan::sync_data (registries, tags, recipes, advancements, ~180 ms) last, after the worldgen bundle and the loot tables.
  • serve() calls preload_sync_data at ~765 ms. By then the preload thread hasn't reached sync_data yet, so SYNC is empty and unlocked, and the server starts a second read on "Server data preload".
  • The preload thread then reaches sync_data (~935 ms), takes SYNC's lock and reads everything again while holding it.
  • SyncPreload::adopt on the server thread blocks on that lock until the second read finishes. That's ~100 ms on the critical path to the first frame.

Startup trace with sub-steps added (HORIZON_STARTUP_TRACE, warm start, --world T --seed 1234, render distance 12):

 764   98 ms  server.game_new        [Server thread]
 764  ~180 ms sync.*                 [Server data preload]   <- first read
 862  109 ms  server.open_world      [Server thread]
 934  ~135 ms sync.*                 [World data preload]    <- second read, holding SYNC
 971  100 ms  server.sync_adopt      [Server thread]         <- waits on the lock
1077   63 ms  server.settle_spawn    [Server thread]

Proposed fix

Read sync_data on its own thread at the start of both preloads, in parallel with the worldgen and loot reads. It then holds SYNC early, preload_sync_data sees it busy or filled and starts nothing, and the server never waits on a second read.

Measured on a Ryzen 7 5800X / RTX 3070 / NVMe, tools/startup_trace.py --world T --seed 1234 --warm, base and fix interleaved, 6 runs each (medians):

before after
server.settle_spawn starts 1094 ms 1004 ms (−90)
world.first_frame 1225 ms 1139 ms (−87)
world.view_full 1906 ms 1872 ms (−34, paced by chunk batches)
Originally created by @Vaspyyy on GitHub (Nov 2, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6726 Originally assigned to: @Vaspyyy on GitHub. > 🤖 Filed by Vaspyyy's AI agent (Claude Code), not by Vaspyyy personally. ## What happens On a launch into a world (`--world`), the server thread spends ~100 ms before `settle_spawn` waiting for data that was already being read, and that data gets read twice. - `preload_launch_world` (and `preload_world_data`) read `lan::sync_data` (registries, tags, recipes, advancements, ~180 ms) **last**, after the worldgen bundle and the loot tables. - `serve()` calls `preload_sync_data` at ~765 ms. By then the preload thread hasn't reached `sync_data` yet, so `SYNC` is empty and unlocked, and the server starts a second read on "Server data preload". - The preload thread then reaches `sync_data` (~935 ms), takes `SYNC`'s lock and reads everything again while holding it. - `SyncPreload::adopt` on the server thread blocks on that lock until the second read finishes. That's ~100 ms on the critical path to the first frame. Startup trace with sub-steps added (`HORIZON_STARTUP_TRACE`, warm start, `--world T --seed 1234`, render distance 12): ``` 764 98 ms server.game_new [Server thread] 764 ~180 ms sync.* [Server data preload] <- first read 862 109 ms server.open_world [Server thread] 934 ~135 ms sync.* [World data preload] <- second read, holding SYNC 971 100 ms server.sync_adopt [Server thread] <- waits on the lock 1077 63 ms server.settle_spawn [Server thread] ``` ## Proposed fix Read `sync_data` on its own thread at the start of both preloads, in parallel with the worldgen and loot reads. It then holds `SYNC` early, `preload_sync_data` sees it busy or filled and starts nothing, and the server never waits on a second read. Measured on a Ryzen 7 5800X / RTX 3070 / NVMe, `tools/startup_trace.py --world T --seed 1234 --warm`, base and fix interleaved, 6 runs each (medians): | | before | after | |---|---|---| | server.settle_spawn starts | 1094 ms | 1004 ms (−90) | | world.first_frame | 1225 ms | 1139 ms (−87) | | world.view_full | 1906 ms | 1872 ms (−34, paced by chunk batches) |
Author
Owner

@Vaspyyy commented on GitHub (Nov 2, 2026):

🤖 Agent: /claim

<!-- gh-comment-id:6567993776 --> @Vaspyyy commented on GitHub (Nov 2, 2026): 🤖 Agent: /claim
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#2196
No description provided.