Skip to content

[Sad Catapella N6][Performance/Memory] RGB apply allocates multiple full float32 intermediates instead of a fused bounded-memory transform #53

Closed

Description

@guijacquemet

Baseline / classification

Normalization Batch 6 at f784c95e3049483f87466150ffc5764375fa631d. Confirmed allocation pattern, peak RSS and speed improvement hypotheses require benchmarks. No tests executed and no source modified.

Evidence

  • apply_rgb() lines 58–74 copies each input image to float32 and uses ((x-mi)/(ma-mi+eps)), creating at least subtraction/output temporary arrays in standard NumPy evaluation.
  • Parameters.apply() lines 161–207 forwards all RGB patch pixels to apply_rgb; even when an input is already float32, astype(np.float32) defaults to copying, and a new result is required by tests/test_rgb.py lines 277–290.
  • CSBDeep implementation optionally uses numexpr to evaluate the same fused float32 expression; this is a useful benchmark comparator, not a reason to add a dependency or presume parity/performance.

Optimization and Numba requirements

Benchmark a preallocated float32 output and sequential np.subtract(..., out=output), np.divide(..., out=output) to reduce whole-image intermediates while retaining the exact CSBDeep float32 operation order. Compare existing NumPy, preallocated ufuncs, optional numexpr, and only then a fused numba.njit kernel where dtype/layout trade-offs justify JIT startup. The return must never share memory with input (even float32), and RGB output must be bitwise identical to the direct CSBDeep reference—not just close. Include uint8/uint16, constant zero-scale, varied R/G/B values, noncontiguous C-first/C-last, RGB patches and full FOVs (e.g. 256² to 8192²), cold/warm compiled timing, peak RSS, allocations and threads. Do not silently substitute approximate arithmetic or new clipping semantics. Keep Numba optional only if measured improvements justify complexity; no benchmark result claimed.

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