Issue #1644: Fix performance issue with zooming - #2102
Open
blayzen-w wants to merge 1 commit into
Open
Conversation
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.
Description
Zooming can have poor performance and result in crashing the browser, breaking the canvas, and very high memory usage.
This is happening because Item.draw is requesting a canvas at extreme sizes when using indirect drawing, where something must be drawn to a separate canvas first and then composited back onto the main canvas.
paper.js/src/item/Item.js
Lines 4451 to 4470 in 92775f5
The bounds from
getStrokeBoundscan be upwards of 25,000+ by 25,000+ at high zoom levels, and that is directly used withCanvasProvider.getContextto get a canvas of that size.paper.js/src/canvas/CanvasProvider.js
Lines 45 to 46 in 92775f5
As soon as the canvas width/height is set, the browser will try to allocate resources for a canvas of that size.
In Chrome you can see the browser memory go from 500mb to 3800mb. The frame time will drop from 1ms to 403ms+. Often this will cause a some kind of crash that will break the canvas. This can cause rendering artifacts and require the page to be reloaded.
This fix will use the current canvas size and transform for the indirect rendering. This will limit the unbounded resource allocation and fix it to the size of the visible canvas. This results in a nearly 400x performance increase at high zoom levels.
Related issues
Checklist
yarn run jshintpasses)I believe the existing tests should cover the change since its part of the core rendering function. But if its doesn't and this PR gains traction I can add something.
Let me know if you can think of any problems with this change and I can look into them. I'll also use this in prod for a while and report back after a few weeks.