Closed Bug 1562032 Opened 5 months ago Closed 5 months ago

Implement progress bar in the Dock icon in a different way in order to save CPU

Categories

(Core :: Widget: Cocoa, enhancement)

All
macOS
enhancement
Not set

Tracking

()

RESOLVED FIXED
mozilla69
Tracking Status
firefox69 --- fixed

People

(Reporter: mstange, Assigned: mstange)

References

(Blocks 3 open bugs, Regressed 1 open bug)

Details

(Keywords: power)

Attachments

(3 files)

When you download a file in Firefox on macOS, we draw a progress bar in the application dock icon. The API we use to do that drawing is slightly inefficient: We create a new NSImage with the combined icon + progress bar drawing, and set that as our application icon.
There's a more efficient API: We can set our own NSView instance as the application dock tile's content view and draw into that NSView. This is also a more modern API and lets us remove another lockFocus call from the code base.

Another thing that drained CPU as part of dock drawing was the progress bar animation: On 10.9 and below, the native progress bar had a wavy pattern that was animated. So we triggered a redraw of the dock icon 8 times per second while the progress bar was visible. Starting on 10.10, the style is different and there is no more wavy pattern, but we were still triggering the redraws unnecessarily.

This patch reimplements the drawing using manual strokes and fills that look similar to the 10.12 progress bar style, and removes the animated redraws.

Two profiles for comparison:
Before: https://perfht.ml/2X4HrvZ, 247ms of dock drawing over the span of 15 seconds
After: https://perfht.ml/2X5O9SL, 16ms of dock drawing over the span of 15 seconds
So in this particular case the patch reduces the CPU impact of dock drawing by 15x.

Attached image "before" screenshot
Attached image "after" screenshot

Bugbug thinks this bug is a enhancement, but please change it back in case of error.

Type: defect → enhancement
Pushed by mstange@themasta.com:
https://hg.mozilla.org/integration/autoland/rev/9823d19217e2
Use NSDockTile to implement the dock download progress bar. r=spohl
Status: ASSIGNED → RESOLVED
Closed: 5 months ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla69
Flags: qe-verify+
Regressions: 1577120
You need to log in before you can comment on or make changes to this bug.