[GH-ISSUE #1961] Windows: the first launch after a Defender signature update takes 77-92 s to load (23,000 loose resource files) #586

Open
opened 2026-11-02 15:40:16 +07:00 by bsakaguchi · 4 comments
Owner

Originally created by @feeldev12 on GitHub (Oct 25, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/1961

Originally assigned to: @ludovic111 on GitHub.

On Windows, the first launch after Microsoft Defender updates its signatures takes 77 to 92 s to load the resources instead of about 5 s. Joining a server or a world waits for rest-ready, so the game looks frozen on the join for over a minute.

What happens

The prepared resources are 23,060 loose files (148 MB): about 4,200 models, 4,200 textures, 2,000 recipes, 1,900 advancements, 1,450 loot tables and so on. Defender's real-time protection scans a file the first time it is opened after a signature update, and its cache of clean files is reset on every update (one or two a day here). Assets::load and the loaders after it open those files one by one, so each scan adds up.

From latest.log, same machine (RTX 3060, Samsung 980 PRO NVMe, 16 threads), same build:

                      warm      first launch after a signature update
load assets           2.43 s    36.54 s
load pack tables      3.24 s    47.05 s
core-ready            3424 ms   47281 ms
load items            3.97 s    59.91 s
rest-ready            5204 ms   77067 ms

The slow runs line up with Defender's signature updates (event 2000 in Microsoft-Windows-Windows Defender/Operational): an update at 16:10 and a slow launch at 17:17, an update at 23:49 and a slow launch at 00:03. Launches between updates are warm, at 5 to 6 s. It isn't the disk: with Defender's cache warm, reading every file serially takes 2.5 s.

Linux and macOS don't scan files on open, so this only shows up on Windows, and only on the first launch after an update. That may be why it hasn't been reported.

Reading in parallel doesn't fix it

Copying the folder makes Defender scan every file, so I timed a copy to estimate the scan cost: 23.9 s with 1 thread, 13.7 s with 8 and 13.6 s with 16. That's about 1 ms a file, and parallel reads only gain 1.75x.

Suggested fix

Keep the prepared resources in one file (an uncompressed archive or a pack file with an index), as vanilla reads them from the client jar. Defender would then scan one file instead of 23,000. Resource packs could stay as they are, looked up before the base file in load order.

It would help resource packs on Windows too. packs::link has no symlinks there, so the overlay copies vanilla's files in every directory a pack touches (crates/horizon-client/src/packs.rs), and each copy is scanned again.

Originally created by @feeldev12 on GitHub (Oct 25, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/1961 Originally assigned to: @ludovic111 on GitHub. On Windows, the first launch after Microsoft Defender updates its signatures takes 77 to 92 s to load the resources instead of about 5 s. Joining a server or a world waits for `rest-ready`, so the game looks frozen on the join for over a minute. **What happens** The prepared resources are 23,060 loose files (148 MB): about 4,200 models, 4,200 textures, 2,000 recipes, 1,900 advancements, 1,450 loot tables and so on. Defender's real-time protection scans a file the first time it is opened after a signature update, and its cache of clean files is reset on every update (one or two a day here). `Assets::load` and the loaders after it open those files one by one, so each scan adds up. From `latest.log`, same machine (RTX 3060, Samsung 980 PRO NVMe, 16 threads), same build: ``` warm first launch after a signature update load assets 2.43 s 36.54 s load pack tables 3.24 s 47.05 s core-ready 3424 ms 47281 ms load items 3.97 s 59.91 s rest-ready 5204 ms 77067 ms ``` The slow runs line up with Defender's signature updates (event 2000 in `Microsoft-Windows-Windows Defender/Operational`): an update at 16:10 and a slow launch at 17:17, an update at 23:49 and a slow launch at 00:03. Launches between updates are warm, at 5 to 6 s. It isn't the disk: with Defender's cache warm, reading every file serially takes 2.5 s. Linux and macOS don't scan files on open, so this only shows up on Windows, and only on the first launch after an update. That may be why it hasn't been reported. **Reading in parallel doesn't fix it** Copying the folder makes Defender scan every file, so I timed a copy to estimate the scan cost: 23.9 s with 1 thread, 13.7 s with 8 and 13.6 s with 16. That's about 1 ms a file, and parallel reads only gain 1.75x. **Suggested fix** Keep the prepared resources in one file (an uncompressed archive or a pack file with an index), as vanilla reads them from the client jar. Defender would then scan one file instead of 23,000. Resource packs could stay as they are, looked up before the base file in load order. It would help resource packs on Windows too. `packs::link` has no symlinks there, so the overlay copies vanilla's files in every directory a pack touches (`crates/horizon-client/src/packs.rs`), and each copy is scanned again.
Author
Owner

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

🤖 Agent: new measurements and a plan, from the client-perf startup work (perf-entry-startup).

How many files the start opens. strace of a start to the title (and 3 s past it) on Linux, with the main branch plus the startup trace from #6496:

opens distinct files
everything under the prepared folder 38,792 22,094
data/minecraft/recipe 14,581 2,043 (each 7-8×: crafting, stations, recipe book ×3, brewing, LAN sync, loot)
assets/minecraft/textures 8,531
data/minecraft/tags 2,623 883
assets/minecraft/models 4,202 4,194

Plus 33,240 stats. With Defender's ~1 ms per file (measured above), 22k distinct files is ~22 s at first launch, and the repeated opens add more.

Plan:

  1. Read each folder once per load. The first PR, perf/recipes-read-once, has the recipe tables share one read of the folder (4 reads → 1 in the rest loader); a PR follows.
  2. Then one file, in #4267's format (horizon-data.bin, written by horizon-prepare from the owner's own copy, never published, mapped, checked at open, with a fallback to today's folders). Its first section is a file table: paths in a string pool with their bytes, which covers #4267's "raw JSON slices" for loot, recipes and advancements and also the assets the client opens at start (models, blockstates, items, textures). Readers go through one read/list API that falls back to the folder, so resource packs and content mods stay as they are. Migrated folder by folder in small PRs, each measured by opens and title time.

/claim

<!-- gh-comment-id:6566864373 --> @ludovic111 commented on GitHub (Nov 2, 2026): 🤖 Agent: new measurements and a plan, from the client-perf startup work (perf-entry-startup). **How many files the start opens.** strace of a start to the title (and 3 s past it) on Linux, with the main branch plus the startup trace from #6496: | | opens | distinct files | |---|---|---| | everything under the prepared folder | 38,792 | 22,094 | | `data/minecraft/recipe` | 14,581 | 2,043 (each 7-8×: crafting, stations, recipe book ×3, brewing, LAN sync, loot) | | `assets/minecraft/textures` | 8,531 | | | `data/minecraft/tags` | 2,623 | 883 | | `assets/minecraft/models` | 4,202 | 4,194 | Plus 33,240 `stat`s. With Defender's ~1 ms per file (measured above), 22k distinct files is ~22 s at first launch, and the repeated opens add more. **Plan:** 1. Read each folder once per load. The first PR, `perf/recipes-read-once`, has the recipe tables share one read of the folder (4 reads → 1 in the rest loader); a PR follows. 2. Then one file, in #4267's format (`horizon-data.bin`, written by `horizon-prepare` from the owner's own copy, never published, mapped, checked at open, with a fallback to today's folders). Its first section is a file table: paths in a string pool with their bytes, which covers #4267's "raw JSON slices" for loot, recipes and advancements and also the assets the client opens at start (models, blockstates, items, textures). Readers go through one `read`/`list` API that falls back to the folder, so resource packs and content mods stay as they are. Migrated folder by folder in small PRs, each measured by opens and title time. /claim
Author
Owner

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

🤖 Agent: /claim

<!-- gh-comment-id:6566871754 --> @ludovic111 commented on GitHub (Nov 2, 2026): 🤖 Agent: /claim
Author
Owner

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

🤖 Agent: a request for anyone on Windows: help measure the Defender case for the single-file change. It takes about 5 minutes, and nothing is sent anywhere.

  1. Start Horizon once, as usual, and quit at the title screen.
  2. In PowerShell (as administrator), run Update-MpSignature. Or wait for Defender's next signature update: event 2000 in Event Viewer → Applications and Services → Microsoft → Windows → Windows Defender → Operational.
  3. Start Horizon again and quit at the title screen.
  4. Post the lines with load assets, core-ready, load items and rest-ready from both starts' latest.log (in Horizon's folder, logs/latest.log), plus your disk (SSD/HDD) and CPU.

Once the single resource file is in a build, the same steps measure the difference.

<!-- gh-comment-id:6568177837 --> @ludovic111 commented on GitHub (Nov 2, 2026): 🤖 Agent: a request for anyone on Windows: help measure the Defender case for the single-file change. It takes about 5 minutes, and nothing is sent anywhere. 1. Start Horizon once, as usual, and quit at the title screen. 2. In PowerShell (as administrator), run `Update-MpSignature`. Or wait for Defender's next signature update: event 2000 in *Event Viewer → Applications and Services → Microsoft → Windows → Windows Defender → Operational*. 3. Start Horizon again and quit at the title screen. 4. Post the lines with `load assets`, `core-ready`, `load items` and `rest-ready` from both starts' `latest.log` (in Horizon's folder, `logs/latest.log`), plus your disk (SSD/HDD) and CPU. Once the single resource file is in a build, the same steps measure the difference.
Author
Owner

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

🤖 Agent: progress on the single data file (horizon-data.bin). All of this is merged on main:

files opened under the prepared root, start → world (strace, Linux) count
before 40,282
#6893: the data file; recipes and loot read from it 27,905
#6976: tags, synchronized registries, advancements 21,991
#7055: textures, models, blockstates, item definitions, HUD atlas 6,740
#7072: trades, paintings, enchantments, particles, ambience, biomes, Fusion scan 4,750

The file is written on an idle thread after the first start, for the vanilla root only. When it is stale or from another root, it is refused and the folders are read as before. Still left: .ogg sounds (deliberately not in the file), worldgen/structure NBTs, and texture folders listed by several scanners.

The Windows/Defender measurement above still needs a volunteer: it is the case these opens cost the most.

<!-- gh-comment-id:6575874262 --> @ludovic111 commented on GitHub (Nov 2, 2026): 🤖 Agent: progress on the single data file (`horizon-data.bin`). All of this is merged on main: | files opened under the prepared root, start → world (strace, Linux) | count | |---|---:| | before | 40,282 | | #6893: the data file; recipes and loot read from it | 27,905 | | #6976: tags, synchronized registries, advancements | 21,991 | | #7055: textures, models, blockstates, item definitions, HUD atlas | 6,740 | | #7072: trades, paintings, enchantments, particles, ambience, biomes, Fusion scan | 4,750 | The file is written on an idle thread after the first start, for the vanilla root only. When it is stale or from another root, it is refused and the folders are read as before. Still left: `.ogg` sounds (deliberately not in the file), `worldgen/structure` NBTs, and texture folders listed by several scanners. The Windows/Defender measurement above still needs a volunteer: it is the case these opens cost the most.
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#586
No description provided.