[PR #205] [MERGED] perf(client): buffer model and render JSON reads #2404

Closed
opened 2026-11-02 15:55:46 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/205
Author: @rdbtCVS
Created: 10/14/2026
Status: ✅ Merged
Merged: 10/14/2026
Merged by: @ludovic111

Base: main ← Head: perf/buffer-json-readers-20261014


📝 Commits (1)

  • 99514c4 perf(client): buffer model and render JSON reads

📊 Changes

3 files changed (+208 additions, -3 deletions)

View changed files

➕ crates/horizon-client/examples/json_readers_bench.rs (+205 -0)
📝 crates/horizon-client/src/models.rs (+2 -2)
📝 crates/horizon-client/src/models/catalog.rs (+1 -1)

📄 Description

Bare File JSON readers issue tiny reads when loading model states and render definitions. Read each resource into a temporary byte buffer and deserialize it with from_slice at the three affected sites: gallery preparation, StateModels::load, and face visibility definitions. The existing two model-state parses remain intact.

The committed json_readers_bench example compares the exact before/after read-and-deserialize expressions and map types, as well as BufReader. It also checks equivalent parsed output and malformed JSON, invalid UTF-8, duplicate-key/Unicode handling, and missing-file errors.

Measurements

Median file-open + read + deserialize time in milliseconds; parsed-tree destruction is outside the timed section. All three readers use identical input files, two warmup loads each, nine samples each with rotated execution order, and black_box. Output equality is asserted before timing.

Resource and destination Bytes Before: File BufReader After: read + slice Before/after
Model states, prepare Map 2,808,833 1392.129 28.984 18.779 74.13x
Model states, catalog BTreeMap 2,808,833 1388.724 27.453 18.810 73.83x
Render definitions, BTreeMap 86,017 40.756 0.675 0.407 100.21x

read + slice also beats BufReader by 1.46–1.66x in these cases. Environment: AMD Ryzen 5 5600X, Linux 7.2.8 x86_64, rustc 1.99.0, Cargo fast optimized profile (no LTO). The filesystem cache is warm and the desktop had other processes running. Prepared production resources were unavailable, so the harness generates representative nested model schemas/states for 1,024 blocks and 57,344 states plus 1,024 render definitions; the model fixture is close to the reported 2.84 MB production input. It accepts a prepared resource directory for future measurements. These are isolated loader measurements, not overall startup or FPS results.

The tradeoff is a temporary allocation equal to each input file's size (about 2.68 MiB for the measured model JSON), released after deserialization.

Validation and reproduction

Passed:

cargo fmt --all -- --check
CARGO_TARGET_DIR=/home/bob/Documents/horizon/target cargo test -p horizon-client --profile fast --example json_readers_bench
CARGO_TARGET_DIR=/home/bob/Documents/horizon/target cargo clippy -p horizon-client --profile fast --lib --example json_readers_bench -- -D warnings

The focused test passes (1 test); Clippy compiles/checks the changed client library and benchmark with warnings denied. Reproduce the synthetic measurement with:

cargo run -p horizon-client --profile fast --example json_readers_bench
# Or use actual prepared files and 9 repetitions:
cargo run -p horizon-client --profile fast --example json_readers_bench -- /path/to/resources 9

🔄 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/205 **Author:** [@rdbtCVS](https://github.com/rdbtCVS) **Created:** 10/14/2026 **Status:** ✅ Merged **Merged:** 10/14/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/buffer-json-readers-20261014` --- ### 📝 Commits (1) - [`99514c4`](https://github.com/horizon-rust/horizon/commit/99514c4b7944d630f0b4eec52ab5c11357207e80) perf(client): buffer model and render JSON reads ### 📊 Changes **3 files changed** (+208 additions, -3 deletions) <details> <summary>View changed files</summary> ➕ `crates/horizon-client/examples/json_readers_bench.rs` (+205 -0) 📝 `crates/horizon-client/src/models.rs` (+2 -2) 📝 `crates/horizon-client/src/models/catalog.rs` (+1 -1) </details> ### 📄 Description Bare `File` JSON readers issue tiny reads when loading model states and render definitions. Read each resource into a temporary byte buffer and deserialize it with `from_slice` at the three affected sites: gallery preparation, `StateModels::load`, and face visibility definitions. The existing two model-state parses remain intact. The committed `json_readers_bench` example compares the exact before/after read-and-deserialize expressions and map types, as well as `BufReader`. It also checks equivalent parsed output and malformed JSON, invalid UTF-8, duplicate-key/Unicode handling, and missing-file errors. ### Measurements Median file-open + read + deserialize time in milliseconds; parsed-tree destruction is outside the timed section. All three readers use identical input files, two warmup loads each, nine samples each with rotated execution order, and `black_box`. Output equality is asserted before timing. | Resource and destination | Bytes | Before: File | BufReader | After: read + slice | Before/after | | --- | ---: | ---: | ---: | ---: | ---: | | Model states, prepare Map | 2,808,833 | 1392.129 | 28.984 | 18.779 | 74.13x | | Model states, catalog BTreeMap | 2,808,833 | 1388.724 | 27.453 | 18.810 | 73.83x | | Render definitions, BTreeMap | 86,017 | 40.756 | 0.675 | 0.407 | 100.21x | `read + slice` also beats `BufReader` by 1.46–1.66x in these cases. Environment: AMD Ryzen 5 5600X, Linux 7.2.8 x86_64, rustc 1.99.0, Cargo `fast` optimized profile (no LTO). The filesystem cache is warm and the desktop had other processes running. Prepared production resources were unavailable, so the harness generates representative nested model schemas/states for 1,024 blocks and 57,344 states plus 1,024 render definitions; the model fixture is close to the reported 2.84 MB production input. It accepts a prepared resource directory for future measurements. These are isolated loader measurements, not overall startup or FPS results. The tradeoff is a temporary allocation equal to each input file's size (about 2.68 MiB for the measured model JSON), released after deserialization. ### Validation and reproduction Passed: ```sh cargo fmt --all -- --check CARGO_TARGET_DIR=/home/bob/Documents/horizon/target cargo test -p horizon-client --profile fast --example json_readers_bench CARGO_TARGET_DIR=/home/bob/Documents/horizon/target cargo clippy -p horizon-client --profile fast --lib --example json_readers_bench -- -D warnings ``` The focused test passes (1 test); Clippy compiles/checks the changed client library and benchmark with warnings denied. Reproduce the synthetic measurement with: ```sh cargo run -p horizon-client --profile fast --example json_readers_bench # Or use actual prepared files and 9 repetitions: cargo run -p horizon-client --profile fast --example json_readers_bench -- /path/to/resources 9 ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 15:55:46 +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#2404
No description provided.