Skip to content

[Lazy Sunday B2][Performance] Run-backed OME-Zarr windows repeatedly walk/stat the entire store during planning and each read #378

Open

Description

@guijacquemet

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

  1. WindowReader.read_window, lines 269–279 calls self._check() before and after each window. _check and _now, lines 335–358 call Fingerprint.of(path) on each check.
  2. Fingerprint.of, lines 57–66 calls source_signature. For OME-Zarr stores inventory.source_signature / store_files, lines 57–106 perform os.walk, stat() on every chunk/metadata file, sorting the results and hashing each path/size/mtime.
  3. A run-backed RunWindowReader.read_window, lines 258–260 also calls _inputs._window_request. _window_request, lines 211–222 calls RunInputs._checked, which in turn calls Fingerprint.of (run_inputs.py lines 410–423). Thus a run-backed pixel window read scans the full store at least three times, independently of cache hits.
  4. window_map.map_plan, lines 175–198 builds a per-window plan. Each WindowReader._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 WindowReader is 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

  1. added
    enhancement
    on Nov 24, 2026
  2. guijacquemet commented on Nov 24, 2026

    @guijacquemet
    ContributorAuthor

    Owner (24 Nov 2026): nice to have, later — labelled enhancement.


    Generated by Claude Code

  3. guijacquemet commented on Nov 26, 2026

    @guijacquemet
    ContributorAuthor

    Measured on real data for #529 (draft PR #571, main at 316be56). This is the plain WindowReader, not the run-backed reader, so the run-backed path adds more walks.

    On the SciVis marmoset_neurons OME-Zarr (1283 files, 64³ chunks), the setup was 16 windows of 256 px with 32-px margins and the cache at cache_plan. _check was timed with a wrapper; its result was unchanged. It runs 3 times per window: plan, before and after.

    workers wall _check time, summed over threads
    1 1.13 s 0.95 s (84% of wall)
    2 2.23 s 3.71 s
    4 3.53 s 12.29 s

    The 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions