Skip to content

[Sad Catapella][Performance/Architecture] Add optional FOV-level worker parallelism to mask relationship scans #108

Open

Description

@guijacquemet

Source-grounded finding

At main d7a538e, mask_scan.scan_masks() lines 370–415 iterates every image serially; within each image it reads every Z/T mask plane and performs _scan_plane() pairwise overlap analysis. No n_jobs or worker pool exists. The same serial path remains in pending PR #66. Confirmed absence of FOV-level concurrency, not a measured slowdown. Separate from #69 (inefficient algorithms within each FOV) and the proposed histogram workers issue.

Proposed design

  • Make each FOV the independently scheduled work unit, including all of its Z/T mask planes and mask types, with a reusable bounded pool and a serial n_jobs=1 path. Design for one-worker-per-FOV task semantics, not one new process per FOV. Prefer reusing the same tested worker orchestration abstraction as histogram processing without importing MorphoRelate internals.
  • Worker receives path/identity, matching mask metadata, validated limits and reads its own pixel buffers. Parent prevalidates inventories, sources and label identity; does not ship large NumPy masks over IPC. Workers return sufficient evidence (object counts, piece-count distribution and overlap contingency/relations) in typed immutable form. Global parent combines in deterministic image order, then computes global median of all object piece counts, not median of medians, and all existing relationship shares/thresholds exactly. Use int64 counts; preserve label-ID semantics, and do not assume mask types co-occur in all FOVs.
  • Consider implementing the algorithmic optimizations of [Audit/Performance] Mask component and pair scans repeat expensive full-plane work #69 and fixing incorrect one-to-one matching [Audit/Correctness] same_objects counts many-to-one IoU overlaps as one-to-one matches #67 before concurrency benchmarking; parallelizing inefficient repeated scans may only multiply memory consumption and CPU work.
  • Bound active FOVs and results using a shared total memory budget; per-FOV masked pixel arrays, union-find and connected-components scratch buffers can be large. Maintain stable progress, deterministic report JSON and identical scientific conclusions for 1/2/4 workers; handle failures, cancelled work, interrupted workers and no partially committed report.
  • Include tests for multi-Z/T, missing mask type, sparse and large int32 labels, many mask types, fragmented labels, 1/2/4 workers, errors in mid/last FOV, and identical report bytes except optional run metadata. Benchmark CPU, throughput, RAM, I/O, pool startup and scheduling overhead on FOV count 1/10/100/1000 and mask sizes 512²/4k²/16k² where feasible. A benchmark may justify no parallelism for small tasks.

UI/CLI

Expose the same concurrency setting with consistent validation for both run and masks commands and notebook where relevant. Do not silently reimplement worker concurrency in multiple UI layers.

Reference MorphoRelate's deterministic spawned FOV scheduler for proven behavior; threads versus processes require empirical selection. No tests or benchmarks were executed in this audit.

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