Closed Bug 1562032 Opened 2 years ago Closed 2 years ago

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


(Core :: Widget: Cocoa, enhancement)

Not set



Tracking Status
firefox69 --- fixed


(Reporter: mstange, Assigned: mstange)


(Blocks 3 open bugs)


(Keywords: power)


(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:, 247ms of dock drawing over the span of 15 seconds
After:, 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
Use NSDockTile to implement the dock download progress bar. r=spohl
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla69
Flags: qe-verify+
Regressions: 1577120
Regressions: 1617360
No longer regressions: 1617360
You need to log in before you can comment on or make changes to this bug.