perf(image): remove per-pixel allocs + redundant merged-image copy (MAPCO-11321) - #256
Draft
shimoncohen wants to merge 1 commit into
Draft
perf(image): remove per-pixel allocs + redundant merged-image copy (MAPCO-11321)#256shimoncohen wants to merge 1 commit into
shimoncohen wants to merge 1 commit into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
LOGIC-2 of MAPCO-11317. Native image-path allocation cleanup — no read-API changes.
Changes
srcPixels.GetValue(i,j), which allocates abyte[]per source pixel. Now reads the whole source buffer once withGetValues()and copies by offset — one allocation instead of one-per-pixel.Flatten()returns an image independent of the collection, so the merged image no longer gets cloned into anew MagickImage(...)just to outlive theusingscope.Output is byte-identical
The
TileScaler/TileMergergolden-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