Repository navigation
Description
Lazy Sunday — Batch 2 (pinned SHA bc73f6cfb84596cd656868a81a7d835a1fd79c8e)
Classification: Confirmed repeated full-store metadata traversal in cached OME-Zarr window paths (algorithmic/I/O inefficiency); no end-to-end slowdown or speedup has been measured. Distinct from #304 (re-decoding pixel tiles) and #350 (per-read cyclic garbage/cross-thread cancellation).
Evidence in actual implementation
WindowReader.read_window, lines 269–279 callsself._check()before and after each window._checkand_now, lines 335–358 callFingerprint.of(path)on each check.Fingerprint.of, lines 57–66 callssource_signature. For OME-Zarr storesinventory.source_signature/store_files, lines 57–106 performos.walk,stat()on every chunk/metadata file, sorting the results and hashing each path/size/mtime.- A run-backed
RunWindowReader.read_window, lines 258–260 also calls_inputs._window_request._window_request, lines 211–222 callsRunInputs._checked, which in turn callsFingerprint.of(run_inputs.pylines 410–423). Thus a run-backed pixel window read scans the full store at least three times, independently of cache hits. window_map.map_plan, lines 175–198 builds a per-window plan. EachWindowReader._window_plan, lines 237–241 does another full fingerprint check and opens image metadata, although every window is for the same plane of the same image. Run-backed plans also recheck once in_window_request.
Asymptotic observation: With W windows and C chunk files, a run-backed map_plan + map_windows path can trigger roughly 5W complete C-file inventory traversals (two per plan, three per read, ignoring other checks): O(WC) filesystem stats before/alongside the O(Wwindow-pieces) pixel work. This is a source-level count, not a measured performance result. The number depends on how the consumer invokes the APIs.
Isolated confirmation (not a repository test)
A scratch reproduction of the inventory functions with 1,000 empty chunk-like files took approximately 0.0097 seconds for one scan and 0.1278 seconds for 20 scans in the audit environment. This only confirms the repeated metadata-work mechanism; it is not a whole-repository benchmark and does not predict performance on SSD/network storage.
Impact
At 5,000+ windows and thousands of chunks (the real-slide workflows motivating #304), per-window full-store stat walks can dominate the workload, especially on shared/network-mounted microscopy archives. Pixel cache decodes do not eliminate these walks. For TIFF the analogous repeated stat is O(1), but each per-window plan also reopens and parses the header.
Suggested fix, preserving scientific integrity
- First, remove redundant validation within a single read: the run-backed route need not take an extra full source fingerprint when
WindowReaderis already performing its pre/post read checks, provided the same recorded fingerprint and refusal semantics remain enforced. - Second, plan a complete window batch from one stable source/header snapshot, validate the fingerprint before and after planning, and reuse immutable axis/layout/piece metadata. Never silently reuse an old plan if the file changes.
- Third, investigate an explicitly designed batch-level OME-Zarr validation strategy (e.g. a verified immutable source snapshot or start/end inventory checks). Do not silently weaken the current per-window change-detection guarantee simply to improve speed. State which consistency model the consumer requests and refuse incompatible modes.
- Add stat-walk counters and correctness tests for source modification during planning and reading; benchmark 1k/10k chunks × 100/1k/5k windows on local and network-like filesystems, TIFF vs OME-Zarr, cache hit/miss and 1/2/4/8 workers. Report wall, filesystem stats, output-byte parity and peak RSS.
No code changed. Numba is not appropriate: metadata traversal, filesystem I/O and hash bookkeeping should be addressed by avoiding repeated work, not JIT-compiling Python loops.
Activity
guijacquemet commentedon Nov 24, 2026
Owner (24 Nov 2026): nice to have, later — labelled enhancement.
Generated by Claude Code
guijacquemet commentedon Nov 26, 2026
Measured on real data for #529 (draft PR #571,
mainat316be56). This is the plainWindowReader, not the run-backed reader, so the run-backed path adds more walks.On the SciVis
marmoset_neuronsOME-Zarr (1283 files, 64³ chunks), the setup was 16 windows of 256 px with 32-px margins and the cache atcache_plan._checkwas timed with a wrapper; its result was unchanged. It runs 3 times per window: plan, before and after._checktime, summed over threadsThe walks contend under threads, so 4 workers are 3.1× slower than 1, with identical outputs. On a 38-file sharded store the walks are cheap (0.56 s of 5.70 s). See #570 for the other part of the thread slowdown.
Generated by Claude Code