Consider using HashBytes instead of HashString in nsRFPService::RandomizePixels
Categories
(Core :: Privacy: Anti-Tracking, enhancement)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox143 | --- | fixed |
People
(Reporter: fklc, Assigned: fklc)
References
Details
Attachments
(2 files, 1 external file, 1 obsolete file)
I tried to profile our canvas randomization by profiling the attached page. On my machine, I get the following:
- HashBytes Method:
- Without profiler 19076ms
- With profiler 20447ms https://share.firefox.dev/406MH5O
- Current (HashString) Method:
- Without profiler 25179ms
- With profiler 26633ms https://share.firefox.dev/4eI4kyU
Looking into the profiles, we see that, for
- Current (HashString) Method: "Traced Running Time" of toDataURL was 26625ms, and 8790ms of it was nsRFPService::RandomizePixels.
- HashBytes Method: "Traced Running Time" of toDataURL was 20430ms, and 2672ms of it was nsRFPService::RandomizePixels.
So, 6118ms change (or 3.28x speedup). The main difference between the two functions seem to be the use of word size. HashString goes 1-byte by 1-byte, where as HashBytes goes word-size by word-size. Given data in https://data.firefox.com/dashboard/hardware, most users should see a performance boost.
| Assignee | ||
Comment 1•1 year ago
|
||
Do note that the attachment takes a while to load because it calls toDataURL 100,000 times.
| Assignee | ||
Updated•1 year ago
|
| Assignee | ||
Comment 2•1 year ago
|
||
| Assignee | ||
Comment 3•1 year ago
•
|
||
This obviously doesn't include the other branch of the if statement (that branch takes 3,244ms for nsRFPService::RandomizePixels)
Comment 4•1 year ago
|
||
I'm not terribly familiar with the profiler or how to consider these results (that the profiler says something is faster but it's being measured as slower...) I'm going to try to find someone to review the patch from that viewpoint.
| Assignee | ||
Comment 5•1 year ago
|
||
Sorry I made a typo. "Current (HashString) Method:" should be changed with "HashBytes Method:" in the first paragraph. I fixed it. I'll also try to add some more benchmarks at different lengths/sizes, and follow up on #perf channel on matrix after adding those.
| Assignee | ||
Comment 6•1 year ago
|
||
Comment 7•1 year ago
|
||
Comment on attachment 9499523 [details]
Bug 1976317 - Skip verify for browser_fpp_protections_matrix_{1,2,3,4}.js tests. r?tjr
Revision D256649 was moved to bug 1975803. Setting attachment 9499523 [details] to obsolete.
| Assignee | ||
Comment 8•1 year ago
|
||
I also compared other sizes.
With HashBytes
Size 10x10: Ran toDataURL() 200000 times and it took 4869 ms
Size 50x50: Ran toDataURL() 100000 times and it took 6058 ms
Size 100x100: Ran toDataURL() 50000 times and it took 5750 ms
Size 200x200: Ran toDataURL() 20000 times and it took 6464 ms
Size 300x300: Ran toDataURL() 10000 times and it took 6359 ms
Size 400x400: Ran toDataURL() 8000 times and it took 8303 ms
Size 500x500: Ran toDataURL() 5000 times and it took 8192 ms
Size 600x600: Ran toDataURL() 3500 times and it took 8099 ms
Size 700x700: Ran toDataURL() 2000 times and it took 6480 ms
Size 800x800: Ran toDataURL() 1600 times and it took 6364 ms
Size 900x900: Ran toDataURL() 1200 times and it took 5987 ms
Size 1000x1000: Ran toDataURL() 800 times and it took 5042 ms
Size 2000x2000: Ran toDataURL() 400 times and it took 9626 ms
With HashString
Size 10x10: Ran toDataURL() 200000 times and it took 4828 ms
Size 50x50: Ran toDataURL() 100000 times and it took 6888 ms
Size 100x100: Ran toDataURL() 50000 times and it took 7669 ms
Size 200x200: Ran toDataURL() 20000 times and it took 9512 ms
Size 300x300: Ran toDataURL() 10000 times and it took 9820 ms
Size 400x400: Ran toDataURL() 8000 times and it took 13479 ms
Size 500x500: Ran toDataURL() 5000 times and it took 12802 ms
Size 600x600: Ran toDataURL() 3500 times and it took 12776 ms
Size 700x700: Ran toDataURL() 2000 times and it took 9889 ms
Size 800x800: Ran toDataURL() 1600 times and it took 10287 ms
Size 900x900: Ran toDataURL() 1200 times and it took 9648 ms
Size 1000x1000: Ran toDataURL() 800 times and it took 7898 ms
Size 2000x2000: Ran toDataURL() 400 times and it took 15756 ms
With HashBytes with profiler
Size 10x10: Ran toDataURL() 200000 times and it took 5165 ms
Size 50x50: Ran toDataURL() 100000 times and it took 6165 ms
Size 100x100: Ran toDataURL() 50000 times and it took 6097 ms
Size 200x200: Ran toDataURL() 20000 times and it took 6748 ms
Size 300x300: Ran toDataURL() 10000 times and it took 6648 ms
Size 400x400: Ran toDataURL() 8000 times and it took 8755 ms
Size 500x500: Ran toDataURL() 5000 times and it took 8601 ms
Size 600x600: Ran toDataURL() 3500 times and it took 8582 ms
Size 700x700: Ran toDataURL() 2000 times and it took 6676 ms
Size 800x800: Ran toDataURL() 1600 times and it took 6789 ms
Size 900x900: Ran toDataURL() 1200 times and it took 6422 ms
Size 1000x1000: Ran toDataURL() 800 times and it took 5146 ms
Size 2000x2000: Ran toDataURL() 400 times and it took 10073 ms
With HashString with profiler:
Size 10x10: Ran toDataURL() 200000 times and it took 5129 ms
Size 50x50: Ran toDataURL() 100000 times and it took 7171 ms
Size 100x100: Ran toDataURL() 50000 times and it took 7989 ms
Size 200x200: Ran toDataURL() 20000 times and it took 9929 ms
Size 300x300: Ran toDataURL() 10000 times and it took 10148 ms
Size 400x400: Ran toDataURL() 8000 times and it took 13888 ms
Size 500x500: Ran toDataURL() 5000 times and it took 13583 ms
Size 600x600: Ran toDataURL() 3500 times and it took 13460 ms
Size 700x700: Ran toDataURL() 2000 times and it took 10473 ms
Size 800x800: Ran toDataURL() 1600 times and it took 10792 ms
Size 900x900: Ran toDataURL() 1200 times and it took 10213 ms
Size 1000x1000: Ran toDataURL() 800 times and it took 8333 ms
Size 2000x2000: Ran toDataURL() 400 times and it took 16337 ms
So in all sizes, HashBytes is faster or equal. As the size gets larger, the difference gets larger too.
| Assignee | ||
Comment 9•1 year ago
|
||
| Assignee | ||
Comment 10•1 year ago
•
|
||
If this speedup is reproducible consistently, we might plug HashStringKnownLength to HashBytes too (just copying over my comment in matrix perf channel)
Comment 11•1 year ago
|
||
Comment 12•1 year ago
|
||
| bugherder | ||
Updated•1 year ago
|
Description
•