Skip to content

perf(image): remove per-pixel allocs + redundant merged-image copy (MAPCO-11321) - #256

Draft
shimoncohen wants to merge 1 commit into
masterfrom
logic-2-image-path
Draft

perf(image): remove per-pixel allocs + redundant merged-image copy (MAPCO-11321)#256
shimoncohen wants to merge 1 commit into
masterfrom
logic-2-image-path

Conversation

@shimoncohen

Copy link
Copy Markdown
Collaborator

LOGIC-2 of MAPCO-11317. Native image-path allocation cleanup — no read-API changes.

Changes

  • TileScaler.Upscale: the nested scaling loop called srcPixels.GetValue(i,j), which allocates a byte[] per source pixel. Now reads the whole source buffer once with GetValues() and copies by offset — one allocation instead of one-per-pixel.
  • TileMerger.MergeTiles: Flatten() returns an image independent of the collection, so the merged image no longer gets cloned into a new MagickImage(...) just to outlive the using scope.

Output is byte-identical

The TileScaler/TileMerger golden-image tests (reference upscaled/merged jpegs & pngs) pass unchanged. Full suite: 1141 passed, 0 failed.

Scope note

The deeper encode→decode→encode round-trip in the merge path is coupled to GetTileFormat's opaque→jpeg behavior, which is MAPCO-4731's concern. Left untouched here to keep format-selection semantics out of this PR. #175 (MAPCO-8749, format-threading) also overlaps this area and is intentionally not folded in.

🤖 Generated with Claude Code

…MAPCO-11321)

Image hot path allocated on every pixel and copied the whole merged image.

- TileScaler.Upscale: read the source pixel buffer once via GetValues() and
  index it by offset instead of calling GetValue(i,j) — which allocates a
  byte[] per source pixel — inside the nested scaling loop.
- TileMerger.MergeTiles: Flatten() already returns an image independent of the
  collection, so keep it directly instead of cloning it into a new MagickImage
  just to survive the using scope.

Output is byte-identical: the TileScaler/TileMerger golden-image tests pass
unchanged.

Note: the deeper encode->decode->encode round-trip is coupled to
GetTileFormat's opaque->jpeg behavior (MAPCO-4731) and is intentionally left
untouched here to keep format-selection semantics out of this change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant