-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Fixes caching of inline images during parsing. #5445
Fixes caching of inline images during parsing. #5445
Conversation
for the mentioned pdf, this reduces render times by 50%: before:
after:
|
/botio-windows test |
From: Bot.io (Windows)ReceivedCommand cmd_test from @Snuffleupagus received. Current queue size: 0 Live output at: http://107.22.172.223:8877/a9fd94bd2e163ba/output.txt |
From: Bot.io (Windows)FailedFull output at http://107.22.172.223:8877/a9fd94bd2e163ba/output.txt Total script time: 2.92 mins
Image differences available at: http://107.22.172.223:8877/a9fd94bd2e163ba/reftest-analyzer.html#web=eq.log |
if the time spend calculating the adler32 checksum is an issue for pdfs where the cache is not hit, we could make a cache for candidates by length and then calculate the adler32 lazy if a second image of same length is encountered. |
Did this patch actually pass the regression tests locally? |
Jonas, I do not think this PR is work in progress. |
ok, i see it. page 14 for example. strange. my best guess is that the checksumming inst as good as it should be. now that i changed it to alllow more than one entry... |
7e47b48
to
163fa7b
Compare
thanks for the heads up @Snuffleupagus - it really is that the checksumming considers two different images as equal. ugh. |
according to what i just read about the adler32, i think that checksumming is not really suitable. because my patch causes more images to be potentially reused, the checksum now generates more false positives. |
could we run a linux bot on the current state? besides the adlr32 weakness, i assume that the only regression difference might be due to the binary mask. |
/botio-windows test |
From: Bot.io (Windows)ReceivedCommand cmd_test from @yurydelendik received. Current queue size: 0 Live output at: http://107.22.172.223:8877/d737f85d40d5df1/output.txt |
From: Bot.io (Windows)FailedFull output at http://107.22.172.223:8877/d737f85d40d5df1/output.txt Total script time: 20.30 mins
Image differences available at: http://107.22.172.223:8877/d737f85d40d5df1/reftest-analyzer.html#web=eq.log |
looks good, doesn't it? |
163fa7b
to
7969fd5
Compare
@@ -221,7 +216,7 @@ var Parser = (function ParserClosure() { | |||
|
|||
imageStream = this.filter(imageStream, dict, length); | |||
imageStream.dict = dict; | |||
if (cacheImage) { | |||
if (adler32) { |
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 is a chance 1:2^32 that adler32 can be 0
Does adler32 slower or faster than https://github.com/mozilla/pdf.js/blob/master/src/core/murmurhash3.js ? |
The failures somewhat expected, but we have to be careful. |
ill measure MurmurHash3_64 and see how it goes. It takes about twice as long. (for the pdf in question 398ms vs 149ms) |
i figured it out. it was not the fact that writing in the cache caused the problem. it was the reading part that never assumed more than one entry in it. |
7969fd5
to
946cebe
Compare
/botio-windows test |
From: Bot.io (Windows)ReceivedCommand cmd_test from @yurydelendik received. Current queue size: 0 Live output at: http://107.22.172.223:8877/9adcf0ad2e2ed3c/output.txt |
From: Bot.io (Windows)FailedFull output at http://107.22.172.223:8877/9adcf0ad2e2ed3c/output.txt Total script time: 18.09 mins
Image differences available at: http://107.22.172.223:8877/9adcf0ad2e2ed3c/reftest-analyzer.html#web=eq.log |
If adler32 speed makes a difference for overall rendering time, then we could also skip the modulo operation, if
(Quick sanity check: |
well it has an impact. i will measure the difference and update the PR, @fkaelberer Its about twice as fast. Great suggestion. Thanks. |
As described in mozilla#5444, the evaluator will perform identity checking of paintImageMaskXObjects to decide if it can use paintImageMaskXObjectRepeat instead of paintImageMaskXObjectGroup. This can only ever work if the entry is a cache hit. However the previous caching implementation was doing a lazy caching, which would only consider a image cache worthy if it is repeated. Only then the repeated instance would be cached. As a result of this the sequence of identical images A1 A2 A3 A4 would be seen as A1 A2 A2 A2 by the evaluator, which prevents using the "repeat" optimization. Also only the last encountered image is cached, so A1 B1 A2 B2, would stay A1 B1 A2 B2. The new implementation drops the "lazy" init of the cache. The threshold for enabling an image to be cached is rather small, so the potential waste in storage and adler32 calculation is rather low. It also caches any eligible image by its adler32. The two example from above would now be A1 A1 A1 A1 and A1 B1 A1 B1 which not only saves temporary storage, but also prevents computing identical masks over and over again (which is the main performance impact of mozilla#2618)
946cebe
to
970c048
Compare
/botio test |
From: Bot.io (Linux)ReceivedCommand cmd_test from @yurydelendik received. Current queue size: 0 Live output at: http://107.21.233.14:8877/e6c84d6e7269dc1/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_test from @yurydelendik received. Current queue size: 0 Live output at: http://107.22.172.223:8877/96be496c0b2908b/output.txt |
From: Bot.io (Windows)FailedFull output at http://107.22.172.223:8877/96be496c0b2908b/output.txt Total script time: 17.13 mins
Image differences available at: http://107.22.172.223:8877/96be496c0b2908b/reftest-analyzer.html#web=eq.log |
From: Bot.io (Linux)FailedFull output at http://107.21.233.14:8877/e6c84d6e7269dc1/output.txt Total script time: 22.51 mins
Image differences available at: http://107.21.233.14:8877/e6c84d6e7269dc1/reftest-analyzer.html#web=eq.log |
/botio makeref Thank you for the patch |
From: Bot.io (Windows)ReceivedCommand cmd_makeref from @yurydelendik received. Current queue size: 0 Live output at: http://107.22.172.223:8877/7d2734ade5d8cf4/output.txt |
From: Bot.io (Linux)ReceivedCommand cmd_makeref from @yurydelendik received. Current queue size: 0 Live output at: http://107.21.233.14:8877/4ce79fafcef6541/output.txt |
Fixes caching of inline images during parsing.
From: Bot.io (Windows)SuccessFull output at http://107.22.172.223:8877/7d2734ade5d8cf4/output.txt Total script time: 17.02 mins
|
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/4ce79fafcef6541/output.txt Total script time: 22.14 mins
|
As described in #5444, the evaluator will perform identity checking of
paintImageMaskXObjects to decide if it can use
paintImageMaskXObjectRepeat instead of paintImageMaskXObjectGroup.
This can only ever work if the entry is a cache hit. However the
previous caching implementation was doing a "lazy" caching, which would
only consider a image cache-worthy if it is repeated.
Only then the repeated instance would be cached.
As a result of this the sequence of identical images A1 A2 A3 A4 would be
seen as A1 A2 A2 A2 by the evaluator, which prevents using the "repeat"
optimization.
Also the previous cache implementation was only checking the last used
image.
Thus the sequence A1 B1 A2 B2 A3 B3 would be 6 instances of images, even
when there are only two different ones.
The new implementation drops the "lazy" init of the cache. The threshold
for enabling an image to be cached is rather small, so the potential waste
in storage and adler32 calculation is pretty low.
Also this implementation will now keep hold of any cachable images. Not
only the last seen image.
The two examples from above would now be A A A A and A1 B1 A1 B1 A1 B1,
which not only saves temporary storage, but also prevents computing
identical masks over and over again (which is the main performance impact
of #2618)