canvas.toDataURI() takes 3x as long in Firefox as in Chrome (with most time spent in MOZ_Z_deflate_slow)
Categories
(Core :: Graphics: ImageLib, defect)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox96 | --- | verified |
People
(Reporter: dholbert, Assigned: tnikkel)
References
(Regressed 1 open bug)
Details
(Keywords: perf:responsiveness)
Attachments
(7 files)
|
203.45 KB,
text/html
|
Details | |
|
1.62 KB,
text/plain
|
Details | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
Details | Review |
STR:
- Load attached testcase.
- Inspect your web console to see how long the data URI serialization of the canvas took.
ACTUAL RESULTS:
In Chrome, the duration is approximately 30ms.
In Firefox, the duration is approximately 100ms.
These durations are pretty reliable for me; I can reload the page and the measurement stays the same.
EXPECTED RESULTS:
Performance on-par with Chrome.
I ran into this at https://kidpix.app , which happens to serialize to a data URL after each click, as part of its "undo" support. So our toDataURL() slowness causes jank on each click there, i.e. each paint operation.
| Reporter | ||
Comment 1•4 years ago
|
||
Firefox Nightly profile: https://share.firefox.dev/3rUUJMG
In this profile, the toDataURL() operation takes 107ms, which is mostly spent in MOZ_Z_deflate_slow.
| Reporter | ||
Comment 2•4 years ago
|
||
Here's a profile of Chrome for comparison:
https://share.firefox.dev/3fDmvZo
This Chrome profile shows about 42ms being spent in toDataURL, which matches my console.log() output from this particular run. (Note there are 66 samples during that period, but that's just because Chrome seems to be doing more than 1 sample per millisecond -- so 66 samples != 66ms.)
| Assignee | ||
Comment 3•4 years ago
|
||
Are we maybe just using a higher compression setting? Logging dataURL.length I get 192214 in Firefox, 293902 in Safari, and 285330 in Chrome.
| Assignee | ||
Comment 4•4 years ago
|
||
Indeed, looks like they set the zlib level to 3
and the default is 6, which we do not ever change (0-9 being the options, which higher values being slower by smaller produced result).
| Assignee | ||
Comment 5•4 years ago
|
||
They also limit the filters to only the sub filter, whereas I think the libpng default is to allow all filters.
| Assignee | ||
Comment 6•4 years ago
|
||
At this link
https://source.chromium.org/chromium/chromium/src/+/217d81bc49377c2235b8325a2f03dfce9ef45f95
in the file
third_party/WebKit/Source/platform/image-encoders/PNGImageEncoder.cpp
you can find Chromium's rationale for the png encoder settings that they use.
| Assignee | ||
Comment 7•4 years ago
|
||
Did a few tests with shippable builds. First number is length of the data url string, second number is the time taken. We seem to have filters disabled for png encoding, and on this testcase they don't seem to help. Changing our zlib level to 3 seems to be a good pick, gets us on par with Chrome's speed and slightly better compression than Chrome (some other setting of the png encoder must still differ because we don't match them exactly with any filter).
nightly, zlib level 6, png write filters disabled
192214
58ms
zlib level 3, png write filters disabled
254810
25ms
zlib level 3, png write filters enabled, PNG_NO_FILTERS
287294
95ms
zlib level 3, png write filters enabled, PNG_FILTER_NONE
254810
27ms
zlib level 3, png write filters enabled, PNG_FILTER_SUB
290130
32ms
zlib level 3, png write filters enabled, PNG_FILTER_UP
281394
33ms
zlib level 3, png write filters enabled, PNG_FILTER_AVG
324938
40ms
zlib level 3, png write filters enabled, PNG_FILTER_PAETH
288610
49ms
zlib level 3, png write filters enabled, PNG_FAST_FILTERS
286970
58ms
zlib level 3, png write filters enabled, PNG_ALL_FILTERS
287294
77ms
chrome
285330
23ms
safari
293902
36ms
| Assignee | ||
Comment 8•4 years ago
•
|
||
I also did a comparison with a photo
photo
nightly, zlib level 6, png write filters disabled
Duration: 251ms
length 4193966
zlib level 3, png write filters disabled
Duration: 129ms
length 3754074
zlib level 3, png write filters enabled, PNG_NO_FILTERS
Duration: 223ms
length 2681950
zlib level 3, png write filters enabled, PNG_FILTER_NONE
Duration: 131ms
length 3754074
zlib level 3, png write filters enabled, PNG_FILTER_SUB
Duration: 149ms
length 2936234
zlib level 3, png write filters enabled, PNG_FILTER_UP
Duration: 134ms
length 2592058
zlib level 3, png write filters enabled, PNG_FILTER_AVG
Duration: 163ms
length 2875366
zlib level 3, png write filters enabled, PNG_FILTER_PAETH
Duration: 159ms
length 2687346
zlib level 3, png write filters enabled, PNG_FAST_FILTERS
Duration: 166ms
length 2573646
zlib level 3, png write filters enabled, PNG_ALL_FILTERS
Duration: 210ms
length 2681950
chrome
Duration: 135.5ms
length 2992822
safari
Duration: 90ms
length 2701834
Updated•4 years ago
|
Updated•4 years ago
|
| Assignee | ||
Comment 9•4 years ago
|
||
Did a further comparison with bug 1737038 fixed.
The interesting thing here is that for photos with the sub filter, zlib level 3 is actually smaller than zlib level 4, in addition to being faster.
The sub filter makes things that are more suitable to png compression larger, and of course going to zlib level 3 increase the size of these types of images as well, but we are much faster, which is the main point here.
| Assignee | ||
Comment 10•4 years ago
|
||
Other than compiler a bit more code this should have no functional effect, we're setting the values to their default values we had before.
Depends on D130020
Updated•4 years ago
|
| Assignee | ||
Comment 11•4 years ago
|
||
Rationale is in the bug. Short version we match what Chrome does for much faster encoding, producing larger files for content that png compression works well for, and smaller files (while still being faster) for photo like content.
Depends on D130021
| Assignee | ||
Comment 12•4 years ago
|
||
I verified that the pngs I'm changing here were pixel identifical before/after.
Depends on D130022
| Assignee | ||
Comment 13•4 years ago
|
||
This lets me write a test for this and lets other consumers tweak the compression settings if they would like.
Depends on D130023
| Assignee | ||
Comment 14•4 years ago
|
||
Depends on D130024
Comment 15•4 years ago
|
||
Comment 16•4 years ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/55ee4bab11fc
https://hg.mozilla.org/mozilla-central/rev/2c630a9af345
https://hg.mozilla.org/mozilla-central/rev/04ee2e8dedff
https://hg.mozilla.org/mozilla-central/rev/df68f8ee22b3
https://hg.mozilla.org/mozilla-central/rev/4b7da81f442b
Updated•4 years ago
|
Comment 17•4 years ago
|
||
Was able to reproduce the issue on Firefox 92.0a1 (2021-08-05) under macOS 12.1 by using the TC provided in Comment 0.
Got substantially lower duration times on Firefox 96.0. Tests were performed under macOS 12.1, Ubuntu 20.04 and Windows 7.
Updated•3 years ago
|
Description
•