Skip to content

[Sad Catapella N7][Performance] image_summaries eagerly retains all FOV histograms instead of supporting bounded-memory per-image aggregation #58

Closed

Description

@guijacquemet

Baseline and classification

Normalization Batch 7 at f784c95e3049483f87466150ffc5764375fa631d. Confirmed eager-memory architecture; benefit of streaming is unmeasured. Coordinate with #49 (CSV reader/writer streaming), #34 (PooledHistogram merge allocations), preprocessing #77 (large histogram tables), and preprocessing #97 (notebook caching). No benchmarks or code changes.

Evidence

  • image_summaries() lines 162–175 first calls records = list(records), holds all histograms, and then builds images: dict[key, list[PlaneRecord]]; iterating over a streaming generator does not bound memory.
  • _summary() lines 178–197 materializes per-channel histogram references and invokes PooledHistogram, which allocates concatenated bin arrays for each image; the full table remains live while each FOV is reduced.
  • Tests use small unsorted datasets and enforce deterministic sorted output; there is no streaming/large-FOV memory test.

Impact / scale

For 10,000 single-Z FOVs × 4 channels × 65,536 bins of int64 counts, retained bin arrays alone occupy ~19.5 GiB, before Python records and PooledHistogram temporaries. This differs from #49 (CSV reader/writer): even if the reader becomes streaming, this analysis function immediately materializes the complete iterator.

Optimization / acceptance

Provide an explicit API for per-image sorted/grouped record streaming, with a documented precondition that all Z/T rows of an image are contiguous and stable; on arbitrary unsorted data use bounded external sort/staging or retain an explicit eager compatibility mode. Emit one ImageSummary per complete FOV and free per-image histogram buffers promptly; preserve global deterministic ordering, channel validation, missing values and percentile definition. Because global channel-cardinality consistency may be learned late, design a fail-safe validation pass or staged publication; never silently emit partially valid results without a clear error contract. Compare eager vs streaming summary rows exactly and verify no duplicates/omissions; benchmark 1k–100k FOVs, 1/4/8 channels, 256/65,536 bins, 1/10/100 Z/T slices, peak RSS, throughput and sorted-vs-unsorted input. The principal gain is memory architecture, not Numba. Respect source/identity checks (#43, #45).

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions