
Dramatically reduced power usage in Firefox 70 on macOS with Core Animation - muizelaar
https://mozillagfx.wordpress.com/2019/10/22/dramatically-reduced-power-usage-in-firefox-70-on-macos-with-core-animation/
======
STRML
This is quite dramatic, in that I can actually _feel_ my Macbook not heating
up as much, nor can I hear the fans anymore.

We do quite a lot of work on a trading website that has heavy use of Canvas
and CSS animations, and the latter really kills performance. Two runs on our
production website from Intel Power Gadget, pre and post upgrade, show
decreased temperature, a lot fewer power spikes, less DRAM wattage, lower GFX
clocks, and about 40% less power overall:

Before: [https://i.imgur.com/WkdWaHx.jpg](https://i.imgur.com/WkdWaHx.jpg)

After: [https://i.imgur.com/3ojMyjT.jpg](https://i.imgur.com/3ojMyjT.jpg)

~~~
KloudTrader
Bitmex looks very interesting, any fun stories to share?

~~~
earthtolazlo
Given the extensive market manipulation and liquidation of margin traders in
cryptocurrency, probably nothing that can be shared publicly.

------
kace91
I've been nagging on HN's comment sections every few months about this issue
whenever a FF related submission made the frontpage... Now I can finally ditch
chrome and start spreading the news so the guys in my office can do it too :D

Even better is the news that it's going to improve even further, and the plans
to include a Metal backend to WebRender...

~~~
heavyset_go
> _I 've been nagging on HN's comment sections every few months about this
> issue whenever a FF related submission made the frontpage..._

Same here, until one of the people responsible for the patches replied to tell
me that he fixed it. I've been running nightly builds of Firefox ever since.

Firefox with NoScript runs fast and cool. I love it.

------
kvark
Amazing work by my colleagues! I hope we'll not regress this with WebRender ;)

Celebration aside, one particular note (that was known, but still) makes me
sad:

> It’s worth noting that the ability to assign an IOSurface to the CALayer
> contents property is not properly documented. Nevertheless, all major
> browsers on macOS now make use of this API.

So we end up in a situation where using the most efficient way to display
contents now relies on undocumented/private APIs. At any point Apple can break
them, or punish us for using them.

~~~
pcwalton
It's "documented" as in "tweeted out by an Apple engineer":
[https://twitter.com/bciechanowski/status/874345241666437120?...](https://twitter.com/bciechanowski/status/874345241666437120?lang=en)

One thing that is _not_ documented is that the IOSurface must have been
created with the 'BGRA' pixel format, or it will silently render as black
instead.

~~~
eyegor
I hope that 'bgra' was at least a typo of 'rgba'

~~~
kornholi
BGRA is a "weird" convention in the graphics world that goes back to at least
OS/2 bitmaps, when there was no wrong answer, and has stuck since then. Since
early GPUs targeted Windows (where BGRA is the native format for GDI/D2D), it
makes sense that it made it this far :)

------
ebg13
What I want is an [https://arewesafariyet.com](https://arewesafariyet.com)
that tracks Firefox's macOS energy usage against Safari's so that I can figure
out when to switch. As far as I can tell, they still have a long way to go to
match Safari in battery life and it would be nice if they had an explicit
tracker set up as a way of prioritizing fixing that.

~~~
Spartan-S63
In addition to battery life, I'd also like things like native PiP mode (if
possible) and native, fullscreen video playback. Better rendering gets closer
to letting Firefox replace Safari for me, but the other features are important
to me, too.

~~~
rebelwebmaster
Native PiP is coming in Firefox 71 (already available for testing on Beta
releases), though Windows-only at first. You can track macOS progress by
following:
[https://bugzilla.mozilla.org/show_bug.cgi?id=1532675](https://bugzilla.mozilla.org/show_bug.cgi?id=1532675)

------
lprd
This is very good news!

Firefox has been my daily driver for well over a year now and I've been
extremely happy with it. The gripe I've had has been the heat/power
consumption.

Props to the dev team!

------
Spartan-S63
This is great to see! One gripe I still have with Firefox is how poorly it
handles video playback (controls and energy consumption) compared to Safari.
This makes me want to use Firefox more often, but Safari will still remain my
daily driver because of native full screen video and PiP mode.

~~~
_emacsomancer_
You can enable PiP mode on Firefox - in `about:config` look at the `picture-
in-picture` options.

------
derekdahmer
Just downloaded a clean install of Firefox 70 but even scrolling a simple site
like Hacker News feels very laggy compared to Chrome.

Not sure whats going on. 2018 Retina MBP with dedicated GPU running Catalina.

~~~
zippergz
I'm not a normal Firefox user — I usually use Chrome and Safari side-by-side.
So I decided to give FF another try with this release, and I agree that the
scrolling performance is noticeably worse in FF than Safari and Chrome on the
same page. I know the link here is about power usage, not performance, but it
makes things feel much less nice.

~~~
Miraste
Firefox touchpad scrolling feels worse than other browsers by default because
of the terrible default inertia and acceleration values. If you're not opposed
to some tweaking, you can get them to feel much more like Safari. Further
reading:
[https://www.reddit.com/r/firefox/comments/63cd0m/how_to_get_...](https://www.reddit.com/r/firefox/comments/63cd0m/how_to_get_firefox_to_scroll_like_safarichrome/)

~~~
supercommand
WOW this explains so much about why my experience with Firefox has felt like
garbage.

Why are the defaults set this way???

~~~
muizelaar
Are you scrolling with a touchpad? Most of those settings don't impact
touchpad scrolling. Is there a particular setting which makes the difference?

~~~
Miraste
Did you try them? Several of the settings labeled "mousewheel" also affect
touchpads. I don't have a touchpad on hand to check but I remember
general.smoothScroll.mouseWheel.durationMaxMS making a difference as well.

------
Noxmiles
Just if someone wonders: "Tagesschau" is a german television news service,
probably the most famous in Germany.

------
CharlesW
Cool! I've been curious about Firefox's progress over the last few years, but
this is what pushed me to download a modern version. Good work, Firefox team!

------
oliwarner
So OpenGL wasn't allowing partial viewport "dirtying" on macOS. Does that mean
Firefox on Linux has an opportunity for a similar gain?

~~~
pcwalton
In theory, yes, via the XPRESENT extension and similar mechanisms on Wayland.
I don't know how well the drivers and window server optimize it though. (I
plan to investigate this at some point.)

~~~
floatboth
Most Wayland compositors track damage obsessively. If you turn on the paint
debug overlay in Weston or something wlroots-based and start typing in e.g.
gnome-terminal (with blinking cursor turned off), you'll see that _only a
single character_ is painted at a time.

Here's a good post: [https://emersion.fr/blog/2019/intro-to-damage-
tracking/](https://emersion.fr/blog/2019/intro-to-damage-tracking/)

To do this with EGL, you need to eglSwapBuffersWithDamage(KHR|EXT) instead of
just eglSwapBuffers:
[https://gitlab.freedesktop.org/wayland/weston/blob/23d01c67a...](https://gitlab.freedesktop.org/wayland/weston/blob/23d01c67a320ab1920e4864f6d182bad93258112/clients/simple-
egl.c#L127) (isn't it nice to have a GL API that's not terrible? :D)

I think I know how to do it, going to try soon. Bugzilled:
[https://bugzilla.mozilla.org/show_bug.cgi?id=1590586](https://bugzilla.mozilla.org/show_bug.cgi?id=1590586)

------
dvcrn
Anyone has insights how power usage compares to safari? I’m team safari for
the past years because it’s just so much easier on the battery than anything
else

~~~
lostgame
Safari is unfortunately still consuming far, far less power on my Mid 2012 MBP
and my 2017 MBP - though there is a significant improvement. Others have
posted exact statistics.

------
Shivetya
Does this help with streaming? In particular I have always had issues with
twitch and firefox.

~~~
kevingadd
Stream video playback would probably invalidate most of the framebuffer
anyway, so I'm not sure how much it would help. It's possible it will make a
difference but probably not much. There are other things they could do along
these lines that would definitely help, though.

------
gok
Good changes, although I find it amusing/discouraging that the "high
complexity" graphics use case is a word processor.

------
sorryitstrue
Can't wait to compare this to Safari, which I don't like but is dramatically
gentler on my macbook's battery.

------
outworlder
> The crucial limitation here is that flushBuffer gives you no way to indicate
> which parts of the OpenGL context have changed. This is a limitation which
> does not exist on Windows

Sigh.

The state of OpenGL on OSX is terrible.

~~~
Angostura
Deprecated, I thought. Just there for legacy support

~~~
outworlder
Ah, you are right, since Mojave.

Yay for proprietary APIs.

------
codedokode
> The crucial limitation here is that flushBuffer gives you no way to indicate
> which parts of the OpenGL context have changed.

Partial window updates have been available in Windows since long ago (in non-
accelerated GDI). Why don't others just copy Windows API instead of inventing
their own poor API?

Maybe there is no partial updates because an application can write directly to
GPU textures and GPU will redraw entire screen anyway?

Also I am not sure that browser needs OpenGL, because you cannot render text
efficiently on GPU anyway and the main content of web pages is text.

> Whenever a layer is mutated in any way, the window manager will redraw an
> area that includes the bounds of that layer, rather than the bounds of the
> entire window.

Then the problem still isn't solved because a layer can be much larger than
changed pixels.

~~~
millstone
Of course Apple has a partial window update API which is the primary drawing
mechanism. flushBuffer maps to OpenGL, and Windows has its own version of this
too (Wingdi::SwapBuffers).

I agree that browsers using OpenGL is...a design you could reach when
measuring for graphics throughput at the expense of all else.

------
trophycase
Wonderful, can't wait to test it out. This is one of the main reasons I still
use Chrome. I can't watch videos on my laptop without hearing my fans go crazy
when using FF

~~~
nobleach
Using Linux, I can't watch youtube or use Google Hangouts for too long before
the fans start going. Google refuses to add GPU support for Linux/Chrome. It's
annoying.

------
markdog12
I don't know any details, but Chrome canary on MacOS has a "metal" flag.

"Vulkan" flag on Android too.

(Post mentioned they plan on implementing metal backend)

------
tambourine_man
Isn’t it worrisome the dependence on OpenGL when it’s been deprecated by Apple
in favor of Metal?

Are there any plans to move of off this API?

~~~
fouc
[https://blog.astropad.com/the-catch-22-of-apple-
apis/](https://blog.astropad.com/the-catch-22-of-apple-apis/) seems relevant

------
_bxg1
Really exciting. This was the one thing keeping me from using Firefox on my
personal laptop.

------
rowanG077
How long till we get video acceleration?

------
MuffinFlavored
How does it compare to Chrome?

------
catalogia
Seems like a wash to me on a non-retina mac. It was fine before and seems fine
now. Does anybody know if this should theoretically help non-retina mac users?

~~~
rubbingalcohol
It won't hurt, but the article pointed out the main performance fail was
coming from all the increased strain that retina displays were causing on
memory and cache. Since retina displays have 4x as many pixels, Firefox was
doing 4x as much work for its inefficient compositing engine doing large full-
scene copies on every frame, and this was pushing the limits of what typical
integrated graphics was able to smoothly pump through bandwidth-wise.

