Repository navigation
Avoid sorting and filtering in hot lookups - #1541
Merged
olivervogel merged 1 commit intoOct 3, 2026
Merged
olivervogel merged 1 commit into
olivervogel merged 1 commit into
Conversation
AbstractColor::channel() ran array_filter() with a closure on every channel lookup, which happens many times per modifier (e.g. ~120 times for 10 modifiers on a small image). Polygon::most*Point() sorted all points to read a single extreme point. Use a plain loop returning the first match and linear scans instead, which keep the same results including ties, as usort() is stable.
deluxetom
approved these changes
Oct 2, 2026
deluxetom
left a comment
Contributor
There was a problem hiding this comment.
Reviewed at 2c4d57e. The results are the same, including ties: for 20,000 random polygons with many equal coordinates, all four most*Point() methods return the same point index as develop. channel() returns the same channel and throws the same exception for a missing channel. The empty-polygon behavior has not changed. Local timing: channel() 243 -> 65 ns, mostLeftPoint() 510 -> 155 ns. Full suite passes in the project Docker image (IM 7.1.2 and 6.9.13). Locally the only failures are the pre-existing JP2/HEIC delegate failures, the same as on develop. PHPStan and PHPCS are clean. CI for this PR has not run yet (workflow awaits approval).
Member
|
Thanks. |
olivervogel
pushed a commit
that referenced
this pull request
Oct 4, 2026
AbstractColor::channel() ran array_filter() with a closure on every channel lookup, which happens many times per modifier (e.g. ~120 times for 10 modifiers on a small image). Polygon::most*Point() sorted all points to read a single extreme point. Use a plain loop returning the first match and linear scans instead, which keep the same results including ties, as usort() is stable.
guillaume-sainthillier
deleted the
feature/linear-color-channel-and-polygon-lookups
branch
October 5, 2026 07:36
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.
AbstractColor::channel()ranarray_filter()with a closure on every lookup, which happens many times per modifier (~120 times for 10 modifiers on a small image).Polygon::most*Point()sorted all points to read a single one.Now a loop returning the first match and linear scans, which keep the same results, including ties (
usort()is stable). Both showed up in profiles of small images (~13% of a pass of 10 modifiers).