New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize trimCanvas #8920
Optimize trimCanvas #8920
Conversation
expect(trimmedImageData.width).toEqual(9); | ||
expect(trimmedImageData.width).toEqual(10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is a bug in the old implementation. Since it is drawn by context.fillRect(10, 20, 10, 5)
, the width should be 10.
pixijs/packages/utils/src/media/trimCanvas.ts
Lines 64 to 71 in e2f27bf
if (bound.right === null) | |
{ | |
bound.right = x + 1; | |
} | |
else if (bound.right < x) | |
{ | |
bound.right = x + 1; | |
} |
Should be bound.right < x + 1
here in the old implementation.
Anyway, with the new implementation in this PR, we can get the correct width.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, good point!
This is awesome. Would be nice to see a performance comparison? How much faster is this? |
It would be roughly |
I don't know something off-hand. There's a benchmark npm package you could try? I'm not looking for anything that rigorous, mostly to understand how much faster relative to current. |
Here's a quick performance comparison: v7.0.4: https://jsfiddle.net/bigtimebuddy/04vm18x6/ (15.038s) This doesn't seem like a huge performance improvement (<10%). Could you run it and see if you see something similar? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works, it's less code, and you fixed the off-by-one error. LGTM.
@bigtimebuddy Similar result here. However, using |
3de5609
to
ec40313
Compare
Description of change
Optimize
trimCanvas
, using the implementation in https://gist.github.com/timdown/021d9c8f2aabc7092df564996f5afbbf. Also a new test for trimming empty canvas is added.Closes #8815.
Pre-Merge Checklist
npm run lint
)npm run test
)