-
Notifications
You must be signed in to change notification settings - Fork 426
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
fix: improve perf of <Resize> by creating the canvas in a side effect #6874
Merged
+47
−32
Conversation
This file contains 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
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
No changes to documentation |
Component Testing Report Updated Jun 13, 2024 3:12 PM (UTC)
|
stipsan
force-pushed
the
refactor-use-async
branch
from
June 10, 2024 09:16
5c21e2c
to
0783182
Compare
stipsan
force-pushed
the
refactor-image-tool-resize
branch
from
June 10, 2024 09:21
0510d1b
to
75d5769
Compare
stipsan
force-pushed
the
refactor-image-tool-resize
branch
from
June 11, 2024 08:03
75d5769
to
ae8e06b
Compare
stipsan
force-pushed
the
refactor-image-tool-resize
branch
from
June 12, 2024 01:43
ae8e06b
to
464b451
Compare
stipsan
force-pushed
the
refactor-image-tool-resize
branch
from
June 12, 2024 18:02
464b451
to
b4eb70d
Compare
juice49
requested review from
a team and
jordanl17
and removed request for
a team
June 13, 2024 14:32
stipsan
force-pushed
the
refactor-image-tool-resize
branch
from
June 13, 2024 15:00
b4eb70d
to
2c0cd17
Compare
juice49
approved these changes
Jun 14, 2024
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 looks great! Thank you!
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.
Description
Currently everytime
<Resize>
renders it callsresize()
before handing it off to thechildren
prop callback.Even though the init of
canvas
is memoized withuseState
, and it's only added to the dom once, in auseEffect
, what happens duringresize
voids any benefits from these optimizations:canvas.height
andcanvas.width
, causing layout trashing and repaint.ctx.drawImage(image, ...)
, which is expensive especially on larger images.This PR changes it to run it in a single layout effect (the reasoning for why a layout effect is used instead of a regular effect is explained in code comments).
The effect only runs if the
image
, ormaxHeight
andmaxWidth
changes. Ensuring that these potentially expensive operations are only run when necessary. With the added bonus that React Compiler can now optimize the<Resize />
componentWhat to review
Check the perf, should be great, and otherwise behave like before.
Testing
Existing tests should cover potential regressions.
Notes for release
Images in the
Hotspot & Crop
tool now render faster, and uses far less memory.