Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upDon't clear canvas by resetting width and height #54
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
evancz
Dec 15, 2014
Member
That is a great find! I can imagine that some saves were placed accidentally, or lived through a refactor that they should not have. Are you interested in taking a swing at putting them in the right places? Based on what I recall about the architecture of the rendering code, there should be distinct transitions between levels:
- step into a
group - step out of a
group - step out of everything to embed HTML
- step back into everything to pick back up with another canvas
I imagine all saves should be on the stepping in and all restores should be on the stepping out. Overall, this sounds like a very plausible improvement!
|
That is a great find! I can imagine that some saves were placed accidentally, or lived through a refactor that they should not have. Are you interested in taking a swing at putting them in the right places? Based on what I recall about the architecture of the rendering code, there should be distinct transitions between levels:
I imagine all saves should be on the stepping in and all restores should be on the stepping out. Overall, this sounds like a very plausible improvement! |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jwmerrill
Dec 15, 2014
Contributor
This might be a little premature. I'm doing some experiments with different ways of clearing the canvas, and they don't totally bear out what I asserted above. I'm going to close this until I collect a little more evidence.
|
This might be a little premature. I'm doing some experiments with different ways of clearing the canvas, and they don't totally bear out what I asserted above. I'm going to close this until I collect a little more evidence. |
jwmerrill
closed this
Dec 15, 2014
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jwmerrill
Dec 16, 2014
Contributor
Here's my inconclusive test: http://jsbin.com/vicawitefi/2/edit?js,output
In this version, you switch between strategies by commenting/uncommenting. I'm not seeing a huge difference between them.
|
Here's my inconclusive test: http://jsbin.com/vicawitefi/2/edit?js,output In this version, you switch between strategies by commenting/uncommenting. I'm not seeing a huge difference between them. |
jwmerrill commentedDec 15, 2014
This issue is part of trying to make animations run more smoothly in Firefox.
Currently, on each draw of a collage, the following is executed:
https://github.com/elm-lang/core/blob/9687580e6f7b012cdee712c2f14471b272c85488/src/Native/Graphics/Collage.js#L324
Resetting the canvas node's height and width serves two purposes:
Unfortunately, it appears that resetting the canvas this way also produces a canvas-sized amount of garbage on every frame in Firefox.
Clearing the canvas can also be accomplished by calling
ctx.clearRect(0, 0, w, h). However, this does not reset the transforms. Transforms can be reset through disciplined use ofctx.save()andctx.restore(), but there are currently saves that are never restored:https://github.com/elm-lang/core/blob/9687580e6f7b012cdee712c2f14471b272c85488/src/Native/Graphics/Collage.js#L313
There are two problems here:
translateandscalein the first two lines of this functionsaveinside the for loop is not matched anywhere by a correspondingrestore.I think there is a potentially large win to be had by using transforms in a more disciplined way so that it is possible to avoid resetting the canvas width and height on every draw if they have not changed.