[PR #5045] [MERGED] Zip: read the directory on open, not the whole archive #6026

Closed
opened 2026-11-03 05:16:43 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5045
Author: @Teiwazik
Created: 10/31/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @ludovic111

Base: main ← Head: fix/pack-list-reads-no-whole-zip


📝 Commits (1)

  • 095342d Zip: read the directory on open, not the whole archive

📊 Changes

1 file changed (+174 additions, -27 deletions)

View changed files

📝 crates/horizon-client-render/src/zip.rs (+174 -27)

📄 Description

🤖 Opened by Teiwazik's AI agent (Claude Code, Claude Opus 5.5), not by Teiwazik personally.

Closes #5043

What changes

Zip::open read the whole archive into memory, and listing the packs opens every zip twice on the render thread. With large packs in the folder, enabled or not, opening the options screen froze the game for minutes.

A Zip opened from a file now keeps the file open and holds only the central directory onward, as Java's ZipFile does. Entries are read at their positions, so clones and threads don't share a cursor.

Parsing is unchanged: the zip crate sees the same bytes as before, including the normalized END record, so the tolerant handling of streamed archives, wrong sizes and folder entries still applies. No caller changes.

Measured

Windows, 16 GB RAM, a world open, the same 10 zips totalling 11 GB in resourcepacks/.

Open options Time Read from disk CPU
Before 309–412 s 22,031 MB 165–253 s
After 0.43–0.50 s 18 MB 1.3–1.8 s

The two runs are not fully alike. "Before" was a client with extra local changes and the 9 GB pack loaded. "After" is this branch, where that pack fell back to the default resources because it doesn't fit the atlas, so memory pressure was lower. The listing reads every zip whether it is loaded or not, so the read figure compares directly. The time difference is not all down to this change.

Worth a look

  • An opened Zip now holds a file handle. Data packs keep theirs in Source::Zip for as long as the DataPack lives, so replacing or deleting that file meanwhile behaves as it does for Java's ZipFile, rather than reading from a private copy. I did not test replacing a zip while it is open.
  • pack_signature still hashes each enabled zip in full on every overlay check (packs/cache.rs). That is separate and not changed here.

Testing

New tests open real files: only the tail is held in memory, entries still read correctly, a directory longer than the 64 KiB END scan works, END counts Java ignores are tolerated, and empty or garbage files are refused. The existing Zip tests pass unchanged.

pr_ready (tools/pr_ready.py --quick on Teiwazik, against origin/main at 9d979caa4, 7 min 20 s)

Check Result
Scope ✅ 1 files, +174 −27
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 495 passed (1 min 26 s)
rustfmt ✅ (13 s)
clippy ✅ (3 min 4 s)
tests: horizon-client-render ✅ 708 passed (2 min 31 s)
doc tests ✅ 0 passed (2 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses

🤖 Generated with Claude Code

https://claude.ai/code/session_01EBqm1v5zTsDGwuZF6XKFjL


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/5045 **Author:** [@Teiwazik](https://github.com/Teiwazik) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/pack-list-reads-no-whole-zip` --- ### 📝 Commits (1) - [`095342d`](https://github.com/horizon-rust/horizon/commit/095342d9b728fc6a5a84f1167fb1244a82fbbc22) Zip: read the directory on open, not the whole archive ### 📊 Changes **1 file changed** (+174 additions, -27 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/zip.rs` (+174 -27) </details> ### 📄 Description > 🤖 Opened by Teiwazik's AI agent (Claude Code, Claude Opus 5.5), not by Teiwazik personally. Closes #5043 ## What changes `Zip::open` read the whole archive into memory, and listing the packs opens every zip twice on the render thread. With large packs in the folder, enabled or not, opening the options screen froze the game for minutes. A `Zip` opened from a file now keeps the file open and holds only the central directory onward, as Java's `ZipFile` does. Entries are read at their positions, so clones and threads don't share a cursor. Parsing is unchanged: the `zip` crate sees the same bytes as before, including the normalized END record, so the tolerant handling of streamed archives, wrong sizes and folder entries still applies. No caller changes. ## Measured Windows, 16 GB RAM, a world open, the same 10 zips totalling 11 GB in `resourcepacks/`. | Open options | Time | Read from disk | CPU | | --- | --- | --- | --- | | Before | 309–412 s | 22,031 MB | 165–253 s | | After | 0.43–0.50 s | 18 MB | 1.3–1.8 s | **The two runs are not fully alike.** "Before" was a client with extra local changes and the 9 GB pack loaded. "After" is this branch, where that pack fell back to the default resources because it doesn't fit the atlas, so memory pressure was lower. The listing reads every zip whether it is loaded or not, so the read figure compares directly. The time difference is not all down to this change. ## Worth a look - An opened `Zip` now holds a file handle. Data packs keep theirs in `Source::Zip` for as long as the `DataPack` lives, so replacing or deleting that file meanwhile behaves as it does for Java's `ZipFile`, rather than reading from a private copy. I did not test replacing a zip while it is open. - `pack_signature` still hashes each enabled zip in full on every overlay check (`packs/cache.rs`). That is separate and not changed here. ## Testing New tests open real files: only the tail is held in memory, entries still read correctly, a directory longer than the 64 KiB END scan works, END counts Java ignores are tolerated, and empty or garbage files are refused. The existing `Zip` tests pass unchanged. **pr_ready** (`tools/pr_ready.py --quick` on Teiwazik, against origin/main at 9d979caa4, 7 min 20 s) | Check | Result | | --- | --- | | Scope | ✅ 1 files, +174 −27 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 495 passed (1 min 26 s) | | rustfmt | ✅ (13 s) | | clippy | ✅ (3 min 4 s) | | tests: horizon-client-render | ✅ 708 passed (2 min 31 s) | | doc tests | ✅ 0 passed (2 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EBqm1v5zTsDGwuZF6XKFjL --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:16:43 +07:00
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#6026
No description provided.