-
Notifications
You must be signed in to change notification settings - Fork 10.3k
[api-minor] Improve performances with image masks (bug 857031) #14777
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
Conversation
I'll hopefully have time to look at this tomorrow, however in the meantime I've got one immediate suggestion: Given the sort of changes that are being made in these PRs, there's always a regression risk (since our test-coverage is likely not perfect) and it seems much easier to figure out exactly where something broke if we space-out the landing slightly. |
/botio test |
From: Bot.io (Windows)ReceivedCommand cmd_test from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.193.163.58:8877/58e9b8c4db27157/output.txt |
From: Bot.io (Linux m4)ReceivedCommand cmd_test from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.241.84.105:8877/45edd53d5a5f3cb/output.txt |
From: Bot.io (Linux m4)FailedFull output at http://54.241.84.105:8877/45edd53d5a5f3cb/output.txt Total script time: 23.94 mins
Image differences available at: http://54.241.84.105:8877/45edd53d5a5f3cb/reftest-analyzer.html#web=eq.log |
From: Bot.io (Windows)FailedFull output at http://54.193.163.58:8877/58e9b8c4db27157/output.txt Total script time: 24.23 mins
|
/botio integrationtest |
From: Bot.io (Linux m4)ReceivedCommand cmd_integrationtest from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.241.84.105:8877/576c8b51dff1439/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_integrationtest from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.193.163.58:8877/6f73b16c79342e6/output.txt |
From: Bot.io (Linux m4)FailedFull output at http://54.241.84.105:8877/576c8b51dff1439/output.txt Total script time: 3.75 mins
|
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 don't think that the integration-test failures are related to this patch, since similar failures were observed elsewhere as well.
How about adding the first page of the document in bug 857031 as a linked reference-test, to ensure that we have proper test-coverage for all this new code?
r=me, since this looks reasonable (although the src/display/canvas.js
-code is one part of the code-base that I'm finding quite difficult to navigate at times).
src/display/canvas.js
Outdated
@@ -1275,6 +1280,16 @@ class CanvasGraphics { | |||
this.cachedCanvases.clear(); | |||
this.cachedPatterns.clear(); | |||
|
|||
for (const cache of this._cachedBitmapsMap.values()) { | |||
for (const canvas of cache.values()) { | |||
if (canvas instanceof HTMLCanvasElement) { |
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 code-path can be taken in Node.js environments as well, right?
In that case I don't believe that HTMLCanvasElement
exists, which would throw an Error here and break things. Hence please add a typeof HTMLCanvasElement !== undefined
check to avoid any problems.
src/display/canvas.js
Outdated
); | ||
const maskCtx = maskCanvas.context; | ||
putBinaryImageMask(maskCtx, img); | ||
const objToCanvas = ctx.mozCurrentTransform; |
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 know that you're just moving pre-existing code, but how about giving this variable a more appropriate name (since I don't see how objToCanvas
actually makes sense)?
src/display/canvas.js
Outdated
cacheKey = isPatternFill | ||
? withoutTranslation | ||
: [withoutTranslation, fillColor]; | ||
cacheKey = JSON.stringify(cacheKey); |
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.
Nit: Maybe just doing something like this instead?
cacheKey = JSON.stringify(
isPatternFill ? withoutTranslation : [withoutTranslation, fillColor]
);
src/display/canvas.js
Outdated
const objToCanvas = ctx.mozCurrentTransform; | ||
|
||
let cache, cacheKey, scaled, maskCanvas; | ||
if ((img.bitmap || img.data) && img.count >= 2) { |
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.
Nit: Maybe using ... && img.count > 1
instead?
/botio test |
From: Bot.io (Linux m4)ReceivedCommand cmd_test from @calixteman received. Current queue size: 0 Live output at: http://54.241.84.105:8877/60ec0a11d072688/output.txt |
From: Bot.io (Linux m4)FailedFull output at http://54.241.84.105:8877/60ec0a11d072688/output.txt Total script time: 2.13 mins
Image differences available at: http://54.241.84.105:8877/60ec0a11d072688/reftest-analyzer.html#web=eq.log |
- it's the second part of the fix for https://bugzilla.mozilla.org/show_bug.cgi?id=857031; - some image masks can be used several times but at different positions; - an image need to be pre-process before to be rendered: * rescale it; * use the fill color/pattern. - the two operations above are time consuming so we can cache the generated canvas; - the cache key is based on the current transform matrix (without the translation part) and the current fill color when it isn't a pattern. - the rendering of the pdf in the above bug is really faster than without this patch.
/botio test |
From: Bot.io (Linux m4)ReceivedCommand cmd_test from @calixteman received. Current queue size: 0 Live output at: http://54.241.84.105:8877/0972f6fcf7ba7b8/output.txt |
From: Bot.io (Linux m4)FailedFull output at http://54.241.84.105:8877/0972f6fcf7ba7b8/output.txt Total script time: 24.08 mins
Image differences available at: http://54.241.84.105:8877/0972f6fcf7ba7b8/reftest-analyzer.html#web=eq.log |
/botio test |
From: Bot.io (Linux m4)ReceivedCommand cmd_test from @calixteman received. Current queue size: 0 Live output at: http://54.241.84.105:8877/aa520e2e6db1bd9/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_test from @calixteman received. Current queue size: 0 Live output at: http://54.193.163.58:8877/1e3fb9fcf5e40d8/output.txt |
From: Bot.io (Linux m4)FailedFull output at http://54.241.84.105:8877/aa520e2e6db1bd9/output.txt Total script time: 23.75 mins
Image differences available at: http://54.241.84.105:8877/aa520e2e6db1bd9/reftest-analyzer.html#web=eq.log |
From: Bot.io (Windows)FailedFull output at http://54.193.163.58:8877/1e3fb9fcf5e40d8/output.txt Total script time: 25.10 mins
|
/botio makeref |
From: Bot.io (Linux m4)ReceivedCommand cmd_makeref from @calixteman received. Current queue size: 0 Live output at: http://54.241.84.105:8877/4d274a910519d93/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_makeref from @calixteman received. Current queue size: 1 Live output at: http://54.193.163.58:8877/90e222f41b3d2fa/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.241.84.105:8877/4d274a910519d93/output.txt Total script time: 22.08 mins
|
From: Bot.io (Windows)SuccessFull output at http://54.193.163.58:8877/90e222f41b3d2fa/output.txt Total script time: 21.19 mins
|
and the current fill color when it isn't a pattern.