perf: bound watcher hashing memory with reusable scratch - #530
Merged
Mohamed Mansour (mohamedmansour) merged 1 commit intoSep 12, 2026
Merged
Conversation
Reuse one 8 KiB content buffer, preserve digest and retry semantics, and enforce the existing file-size cap during reads. Add regression coverage, registered benchmarks, and documentation of the memory and mixed latency tradeoffs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Sep 11, 2026
Bang Lee (Qusic)
approved these changes
Sep 12, 2026
Mohamed Mansour (mohamedmansour)
deleted the
mohamedmansour/bounded-watcher-hashing
branch
September 12, 2026 01:00
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reuse one 8 KiB content buffer per watcher instead of allocating a whole-file buffer for each hash. Retain the existing standard-hasher digest, unchanged-save suppression, and retry-after-error behavior.
Regular-file metadata is checked before and after opening. Incremental reads accept files up to 8 MiB and probe one additional byte to detect growth after metadata. Short/interrupted reads are handled; failures and oversized input do not cache partial hashes and still trigger normal invalidation.
Add focused regression coverage, a five-case Criterion benchmark, benchmark-registry coverage, and specification/benchmark documentation. Criterion is an existing workspace dev dependency; no production dependency, public API, CLI processing, streaming writer, or pool behavior changes are included.
This is a bounded-memory improvement with mixed latency results, not a claim that all watcher workloads become faster. The 1 MiB file and small-file burst regressions are retained below.
Source-derived allocation/storage change
These figures follow the implementation and are not measured process-RSS deltas.
Vecallocation per hashPath, event, and hash-map allocations are unchanged. An allocator can retain freed buffers, so source-level storage and cumulative allocation must not be equated with RSS.
Recorded release benchmarks
This PR is based on newer main
2dab6fc6; these timings were not rerun against that newer base. The intervening main commits did not change watcher hashing. The original complete evidence remains associated with #527.Method: release Criterion, 50 samples, 1 second warmup, 3 second target measurement, hot page cache. File opening and metadata are timed; fixture creation is not. Shared Intel Core Ultra 9 285K / Linux x86_64 WSL2 environment, Rust/Cargo 1.98.0. Host load/frequency/cache variation limits interpretation; these are not end-to-end rebuild measurements.
Values are extracted median/P50 estimates and median 95% confidence intervals, in microseconds. They are not Criterion's printed regression/mean estimates.
Additional bounded read calls are a real potential latency/CPU cost. The justification is predictable content-buffer memory and removal of repeated file-sized allocations, with the mixed timing tradeoff explicitly accepted for this dev-server path. No allocator-count trace or process-RSS improvement is claimed.
Reproduction
Run the same newly added harness against the original and changed hashing implementation:
Read each Criterion case's
median.point_estimateandmedian.confidence_intervalfromestimates.json, converting nanoseconds to microseconds.cargo xtask bench allnow includes this harness.Coverage and validation
Tests cover digest equivalence across varied short-read boundaries and repeated interruptions, empty/multiple-buffer/exact-cap input, bounded overflow reads, deterministic growth after metadata, failures before/after partial reads, buffer reuse after failure, missing/non-regular files, and retry/recreation behavior.
cargo test -p microsoft-webui-dev-server, the focusedxtaskbenchmark-registry selection, and completecargo xtask checkpassed on this independent branch. The full gate completed in 77.4 seconds, including benchmark smoke, docs, and workspace/WASM/example builds.No streaming hard limit from #527 is included or required. This PR can merge independently of the CLI improvement in #529.