Repository navigation
Conversation
…rmediate scratch buffers Each worker thread in dstorage::work() processes requests sequentially, but previously constructed a fresh ~10.5 KiB DecompressorOxide and allocated/zero-filled new Vec<u8> buffers for file sources and zlib+BCPack intermediate output on every request. Keep a worker-local WorkerScratch in work() with a boxed miniz_oxide::inflate::core::DecompressorOxide (reset via init() before each stream) plus reusable source and intermediate Vec<u8> buffers (trimmed back after >8 MiB outliers so idle worker RSS stays bounded). Bit-identical inflate status and output verified across valid, short-output, bad-header, bad-Adler32, truncated, and error-recovery cases. Disjoint from Marvisak#2904 and Marvisak#2883; zero new dependencies. Measured (--release bench_dstorage_worker_scratch, median of 3 runs): - 256 KiB x400: 48.03 ms -> 27.61 ms (1.74x, -42.5%) - 32 KiB x2000: 30.21 ms -> 28.79 ms (1.05x, -4.7%) - 4 KiB x8000: 48.24 ms -> 44.41 ms (1.09x, -7.9%) Assisted-by: T3 Code (Antigravity, gemini-4-neon)
kotekompotek
left a comment
There was a problem hiding this comment.
Verified: per-worker scratch is sound since each worker runs one request at a time. init() yields fresh decompressor state before each stream (tables included), flags match the old decompress_slice_iter_to_slice semantics (zlib header + non-wrapping output), and non-Done statuses still map to INVALID_DATA. The 8 MiB retain cap prevents one oversized request from pinning worker memory, and buffer reuse keeps the source/intermediate borrows disjoint.
fuzeofficlal
left a comment
There was a problem hiding this comment.
Reviewed fbfe80ed against main (63bcca43) — worker-local scratch and DecompressorOxide reuse looks sound:
- Decoder and source/intermediate buffers stay strictly worker-local outside the scheduler lock (
dstorage.rs:450-469),init()cleanly resetsminiz_oxide's state machine (preserving zlib header checks, Adler-32 validation, and error mapping), and the new test covers reuse after malformed, truncated, and output-limited inputs. - Two notes to keep in mind:
- With
8 MiBper retained buffer (16 MiBper worker), idle workers can retain up to16 MiB × worker_count(e.g.,~1 GiBat 64 workers), and scheduler staging accounting (514-530, 657-667) covers buffered file input without the zlib-to-BCPack intermediate buffer. - Minor merge overlap with #2987 around
dstorage.rs:461-465(worker loop callingexecute/count/finish), straightforward to combine by trimming scratch before reacquiring the lock and dropping #2987'sQueuedRequestbefore publishing completion.
- With
|
16 GiB Linux/Wine laptop verification, exact PR head This is a useful component of the larger host-RAM work, but the opt-in application-wide admission/reclaim budget is tracked separately in #3012. Please keep its RAM benefit claims scoped to measured scratch and add a guarded matched title/RAM sample before describing the world-load impact on a 16 GiB machine. |
|
NVIDIA full-suite run, to go with the reports above by pickles976, since none of them names a GPU run. Tested exact head Tested
Not tested
AI use
|
|
Automated triage for the maintainers. Merge candidate. Each What I checked:
Minor and optional: the CI: passing. A tester also ran the full suite on an RTX 5070 Ti with no new failures. Recommending a look, not approving. Generated by Claude Code |
…Oxide and source/intermediate scratch buffers
Dukestar69
left a comment
There was a problem hiding this comment.
Tested locally merged onto origin/main (63bcca4) on Windows 11 x64:
cargo test -p victory-hle dstorage: all tests passed.cargo clippy -p victory-hle --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Desamodeth
left a comment
There was a problem hiding this comment.
fbfe80ed has a repeatable allocation cliff on the file-source path. Alternate 5 MiB and 6 MiB requests on one worker: Vec::resize grows the 5 MiB buffer to 10 MiB, then trim() drops it. Both requests are below the 8 MiB cap. The intermediate buffer uses the same growth policy.
Windows x64, Ryzen 7 9800X3D, Rust 1.98.1 release. I used the extracted read_source/read_into functions on the same warm local file. Medians of 12 interleaved batches of 32 reads:
| File read sizes | main 63bcca43 |
PR | capped growth |
|---|---|---|---|
| 5 MiB throughout | 23.04 ms | 10.22 ms | 10.15 ms |
| 5 / 6 MiB alternating | 25.08 ms | 29.95 ms | 11.89 ms |
| 5 MiB / (8 MiB + 4 KiB) | 29.44 ms | 34.85 ms | 34.79 ms |
On the 5/6 trace, growth events fell from 32 to 2 and peak source Vec capacity from 10 to 8 MiB. The revised worker retains 8 MiB at the end of that trace; the current PR retains zero. A second run in reversed order gave 29.60 → 11.48 ms. The above-cap control still released the buffer. Matched file bytes checked separately. These are file-read and scratch measurements only; no decompression, GPU, title run or process RSS measurement.
Tested change for both resize sites
fn grow_scratch(bytes: &mut Vec<u8>, len: usize) {
if len <= bytes.len() {
return;
}
if len > bytes.capacity() && bytes.capacity() > SCRATCH_RETAIN_CAP / 2 {
bytes.reserve_exact(len.max(SCRATCH_RETAIN_CAP) - bytes.len());
}
bytes.resize(len, 0);
}Call grow_scratch(scratch, size) in read_source and grow_scratch(intermediate, inter_size) in execute, keeping trim() as written. Regression case: grow both buffers to 5 MiB, then 6 MiB, then 8 MiB, trimming and checking both still hold the requested length after each step. Grow one to 8 MiB + 1 and check trimming releases only that buffer. Isolated checks passed; I did not run the workspace suite.
AI-assisted with Codex.
Each worker thread in
dstorage::work()processes requests sequentially, but previously constructed a fresh ~10.5 KiBminiz_oxide::inflate::core::DecompressorOxideand heap-allocated + zero-filled newVec<u8>buffers for file sources and zlib+BCPack intermediate buffers on every request.Keep a worker-local
WorkerScratchinwork()holding:DecompressorOxidereset viainit()before each zlib stream (matchingdecompress_slice_iter_to_slice(..., true, false)flags and status mapping bit-for-bit without re-zeroing Huffman tables).sourceandintermediateVec<u8>buffers, trimmed back after any outlier request exceeding 8 MiB (SCRATCH_RETAIN_CAP) so idle worker RSS stays bounded.Leaves
open_file,FACTORY_VTABLE,scheduler,read_into, andinto_destinationuntouched (zero overlap with #2904 and #2883; zero new dependencies).Measured (
--release bench_dstorage_worker_scratch, median of 3 runs)48.03 ms → 27.61 ms(1.74×, -42.5%)30.21 ms → 28.79 ms(1.05×, -4.7%)48.24 ms → 44.41 ms(1.09×, -7.9%)Verification
--tests+--features diagnosticsclippy,xtask policy, full workspace tests): RVZO6/VIctory CI run #45738573777 (green, combined Wave 8 check on63bcca4).reused_decompressor_matches_fresh_on_valid_and_error_streams(exact parity vsdecompress_slice_iter_to_sliceacross valid, short-output, empty, bad-header, bad-Adler32, truncated, output-too-small, and post-error recovery cases) andworker_scratch_reuses_capacity_and_trims_outliers.AI-assisted: T3 Code (Antigravity, gemini-4-neon).