fix(layout): Copy model input to disk in 1 MiB chunks

Merged
CY
1mo ago
+43-1

Summary

process_data_with_model now copies its input to the temporary file in 1 MiB chunks instead of reading the whole input into memory first. For a file-backed upload, the transient copy no longer scales with the input: it stays bounded by the chunk size regardless of input size.

In-memory BytesIO inputs, which the hi_res path uses, see no change. BytesIO.read() from position 0 already returns its buffer without copying.

Behavior

  • Unchanged: the resulting temporary file, the API and supported file sizes.
  • Copy time is unchanged in practice; 1 MiB chunks are slightly faster than both read() and the 64 KiB copyfileobj default.

Validation

  • A new regression test checks that the source is never read without a size bound, and that the copied bytes and forwarded arguments are unchanged.
  • Inference suite (non-slow) passes on the rebased branch. Ruff passes.

Release

Targets 1.6.15 together with #520: both set __version__ to 1.6.15 and add their entry under a shared ## 1.6.15 CHANGELOG section. Whichever merges second keeps 1.6.15 and only moves its bullet into the existing section.