GNOME Shell and Mutter: better, faster, cleaner

The very first update in the series is about GNOME Shell and Mutter. I’ve been increasingly involved with the development of those two core components of GNOME, and recently this has been the focus of my development time.

Fortunately, Endless allows me to use part of my work time to improve it. Naturally, I prioritize my upstream work considering what will impact Endless OS the most. So far, that lead to a series of very nice improvements to Mutter and GNOME Shell.

GNOME Shell

Most of my work time dedicated to GNOME Shell was oriented to performance and cleanup. At Endless, we have a modified GNOME Shell that constantly needs to be rebased. Since I’m taking care of these rebases now, it makes sense for me to also make myself familiar with the vanilla GNOME Shell codebase.

ShellGenericContainer

I’ll start with the work that makes me the proudest: removing the Shell.GenericContainer class.

First, a bit of history.

There was a time when GJS, the JavaScript engine that GNOME Shell is based on, did not support subclassing GObjects and overriding virtual functions. We could only instantiate GObject-based classes, and subclass them, all thanks to GObject-Introspection, but not override their virtual functions. This made, for example, implementing ClutterContent in JavaScript impossible.

For that reason, GNOME Shell developers created ShellGenericContainer: an actor that sends signals for various virtual functions. Because GJS supports signals, that worked well.

There are a few problems with that approach though:

  • Signals are slow, and should not be used on hot paths like layouting or rendering;
  • Going in and out of JavaScript territory is expensive;
  • It makes the JavaScript code slightly more complicated;

Thanks to the fantastic work by Jasper St. Pierre, GJS now supports overriding virtual functions. And that made Shell.GenericContainer obsolete. So I spent quite some time untangling it from GNOME Shell, and results were positive:

https://gitlab.gnome.org/GNOME/gnome-shell/uploads/b61233544ada29773b87de08e48beeb8/ShellGenericContainer.png
In general, running GNOME Shell without Shell.GenericContainer (blue line) led to more stable framerates compared to the current state (red line).

This is now merged and will be available with GNOME Shell 3.32, to be released on March 2019.

Improvements to the texture cache

After various investigations, another potential improvement that showed up was on StTextureCache. Textures (icons, image files, etc) are cached in GNOME Shell by StTextureCache, and that happened by keeping a ClutterTexture object alive.

That turned out to be a problem.

ClutterTexture is deprecated. Clutter has a new interface for drawing the contents of an actor: ClutterContent. It does not necessarily make the code faster, but it allows different actors to share a single ClutterContent without having to override ClutterActor.paint(). In other words, it is a nice and sane abstraction layer to control what an actor is drawing.

So I went ahead and wiped out ClutterTexture from StTextureCache. Then wiped it out entirely from GNOME Shell.

Unexpectedly, it made a small but noticeable difference! Icons are now slightly faster to load, but the most visible impact was in the startup animation.

Mutter

I did not know how fun and exciting compositors could be. It definitely is a new passion of mine, working on Mutter! So much has happened that it’ll be hard to summarize.

Goodbye, Autotools

During last year’s GUADEC, Jonas Ådahl worked on a Meson port of Mutter. After a series of reviews, and a few follow-up fixes, it reached almost complete feature parity with Autotools – the only exception being installed tests.

So I went ahead and added installed tests to the Meson build too.

And also removed Autotools.

Naturally, builds are much faster now. Saving us a few minutes per day.

Wayland vs X11

Another area that was interesting to work on was untangling X11-specific code from Wayland, and vice-versa. There are a handful of developers working on that already, and I had my fair share in better splitting X11 and Wayland code paths in Mutter.

Specifically, I worked on splitting X11-specific code from MetaWindowActor into subclasses. Mutter already handles different surfaces correctly; on X11 sessions, all surfaces are MetaSurfaceActorX11, and under Wayland, MetaSurfaceActorWayland.

MetaWindowActor has now the same split: Wayland windows have a MetaWindowActorWayland associated, while X11 windows have MetaWindowActorX11.

Interestingly, XWayland windows are X11 windows with a Wayland surface. You can check that using GNOME Shell’s Looking Glass:

wayland vs x11.gif
Example of a Xwayland window; it has a MetaSurfaceActorWayland surface, and a MetaWindowActorX11 actor associated.

There’s a lot more happening in this front, but I’ll spare the words for now. You’ll hear more about it in the future (and not necessarily from me).

CPU-side picking

More recently, I’ve been experimenting with the Cogl journal and ironing out a few bugs that are preventing a completely CPU-side picking implementation.

Picking is the process to figure out which element is beneath the cursor. There are two big approaches: geometry-based, and color-based. On games, the latter is the usual approach: each object in the scene is drawn with a plain color, and the final image is read to find out the color beneath a point. Geometry-based picking is what browsers usually do, and it’s basically math around rectangles.

Clutter uses color-based picking, but has a nice feature around that: a journal that tracks drawing operations and, under some conditions, hits an optimized path and does geometry-based picking. This is interesting for Mutter and GNOME Shell because it avoids sending draw operations to the GPU unecessarily when picking, reducing resource usage.

Unfortunately, due to various bugs and implementation details, we do not hit this optimization, causing GPU commands to be issued when they could be avoided.

Figuring out these bugs is what I’ve been experimenting with lately.

 


 

There’s much more that happened, so I will probably do a part 2 of this article soon. But those are big points already, and the post is becoming lengthy.

Many of these experiments and investigations already landed, and will be available with GNOME 3.32. This is all valuable work that is partially sponsored by my employer, Endless, and I’m happy to keep working on it!


53 responses to “GNOME Shell and Mutter: better, faster, cleaner”

  1. […] Stavracas, a developer who did a lot of the work, lays out a lot of technical details on his blog. A number of improvements result in improved frame rates, smoother startup animations, and faster […]

  2. […] Stavracas, a developer who did a lot of the work, lays out a lot of technical details on his blog. A number of improvements result in improved frame rates, smoother startup animations, and faster […]

  3. […] Stavracas, a developer who did a lot of the work, lays out a lot of technical details on his blog. A number of improvements result in improved frame rates, smoother startup animations, and faster […]

  4. […] Stavracas, a developer who did a lot of the work, lays out a lot of technical details on his blog. A number of improvements result in improved frame rates, smoother startup animations, and faster […]

  5. […] Stavracas, a developer who did a lot of the work, lays out a lot of technical details on his blog. A number of improvements result in improved frame rates, smoother startup animations, and […]

  6. […] Stavracas, a developer who did a lot of the work, lays out a lot of technical details on his blog. A number of improvements result in improved frame rates, smoother startup animations, and faster […]

  7. […] Stavracas, a developer who did a lot of the work, lays out a lot of technical details on his blog. A number of improvements result in improved frame rates, smoother startup animations, and faster […]

  8. […] mismo, el encargado de dar más buenas noticias ha sido uno de los desarrolladores de Endless OS, al que permiten trabajar en estos temas y, apoyado en otros componente creador por el proyecto […]

  9. […] mismo, el encargado de dar más buenas noticias ha sido uno de los desarrolladores de Endless OS, al que permiten trabajar en estos temas y, apoyado en otros componente creador por el proyecto […]

  10. […] mismo, el encargado de dar más buenas noticias ha sido uno de los desarrolladores de Endless OS, al que permiten trabajar en estos temas y, apoyado en otros componente creador por el proyecto […]

  11. […] GNOME Shell and Mutter: better, faster, cleaner 3 by anuragsoni | 0 comments on Hacker News. […]

  12. […] GNOME Shell and Mutter: better, faster, cleaner 3 by anuragsoni | 0 comments on Hacker News. […]

  13. […] GNOME Shell and Mutter: better, faster, cleaner 5 by anuragsoni | 0 comments on Hacker News. […]

  14. […] GNOME Shell and Mutter: better, faster, cleaner 5 by anuragsoni | 0 comments on Hacker News. […]

  15. […] GNOME Shell and Mutter: better, faster, cleaner 5 by anuragsoni | 0 comments on Hacker News. […]

  16. […] GNOME Shell and Mutter: better, faster, cleaner 5 by anuragsoni | 0 comments on Hacker News. […]

  17. […] GNOME Shell and Mutter: better, faster, cleaner 7 by anuragsoni | 0 comments on Hacker News. […]

  18. Hi, Feaneron. Congratulations! I am really waiting to test 3.32. I’m following this blog via my aggregator.

  19. Thank you for your work on these core components which serve me well during a significant part of my daily life – and also sharing your dev story with us!

  20. Thanks a lot for your hard word, it certainly must be quite the challenge to tackle these kind of items! 🙂

    1. hard work … spelling errors: the only thing that still work time after time

  21. Omar Hussain Avatar
    Omar Hussain

    Fantastic! Thank you for your efforts – looking forward to these updates to Gnome. 🙂

  22. Lapo Calamandrei Avatar
    Lapo Calamandrei

    Thanks for being awesome as usual.

  23. […] Stavracas, a developer who did a lot of the work, lays out a lot of technical details on his blog. A number of improvements result in improved frame rates, smoother startup animations, and faster […]

  24. […] E’ atteso un importante miglioramento prestazionale per quanto riguarda Gnome Shell e Mutter dopo un’ampia rivisitazione del codice sorgente. […]

  25. […] E’ atteso un importante miglioramento prestazionale per quanto riguarda Gnome Shell e Mutter dopo un’ampia rivisitazione del codice sorgente. […]

  26. […] E’ atteso un importante miglioramento prestazionale per quanto riguarda Gnome Shell e Mutter dopo un’ampia rivisitazione del codice sorgente. […]

  27. […] der beschleunigten GNOME-Shell berichtete Entwickler Georges Stavracas bereits im Januar in seinem Blog. Er zählt eine Reihe von Verbesserungen auf, die zu verbesserten Bildraten, sanfteren […]

  28. […] as animações, a grade de ícones e o painel superior mais rápidos. O desenvolvedor do GNOME, Georges Stavracas, tem informações técnicas sobre algumas das melhorias no desempenho do GNOME Shell e do Mutter […]

  29. […] more details on what has helped improve GNOME performance, read this blog by Georges Stavracas (one of the main developers on the work that brought about these […]

  30. […] more details on what has helped improve GNOME performance, read this blog by Georges Stavracas (one of the main developers on the work that brought about these […]

  31. […] more details on what has helped improve GNOME performance, read this blog by Georges Stavracas (one of the main developers on the work that brought about these […]

  32. […] more details on what has helped improve GNOME performance, read this blog by Georges Stavracas (one of the main developers on the work that brought about these […]

  33. […] more details on what has helped improve GNOME performance, read this blog by Georges Stavracas (one of the main developers on the work that brought about these […]

  34. […] extra particulars on what has helped enhance GNOME efficiency, learn this weblog by Georges Stavracas (one of many major builders on the work that caused these […]

  35. […] more details on what has helped improve GNOME performance, read this blog by Georges Stavracas (one of the main developers on the work that brought about these […]

  36. […] more details on what has helped improve GNOME performance, read this blog by Georges Stavracas (one of the main developers on the work that brought about these […]

  37. […] more details on what has helped improve GNOME performance, read this blog by Georges Stavracas (one of the main developers on the work that brought about these […]

  38. […] more details on what has helped improve GNOME performance, read this blog by Georges Stavracas (one of the main developers on the work that brought about these […]

  39. […] more details on what has helped improve GNOME performance, read this blog by Georges Stavracas (one of the main developers on the work that brought about these […]

  40. […] die das System verlangsamt haben, und die Gnome-Entwickler haben an den Leistungs-Schrauben der Gnome Shell und ihres Fenster-Managers Mutter […]

  41. […] Mutter和GNOME Shell在此发行版中应该会更快,这要归功于基础数据结构的多项性能改进,这些属性使动画,图标网格和顶部面板更快,更灵活。此外,从主循环中删除了一些阻止操作,这应该可以修复GNOME开发人员Georges Stavracas在他的博客上看到了一些有关GNOME Shell和Mutter性能改进的技术信息。 网志由于跟踪器SQL的改进,在许多GNOME应用程序中的搜索也变得更快。 […]

  42. […] que hizo gran parte del trabajo, establece una gran cantidad de detalles técnicos sobre su blog. Una serie de mejoras se traducen en velocidades de fotogramas mejoradas, animaciones de inicio […]

  43. […] que hizo gran parte del trabajo, establece una gran cantidad de detalles técnicos sobre su blog. Una serie de mejoras se traducen en velocidades de fotogramas mejoradas, animaciones de inicio […]

  44. […] ein Entwickler, der einen Großteil der Arbeit geleistet hat, legt viele technische Details dar sein Blog. Eine Reihe von Verbesserungen führen zu verbesserten Bildraten, flüssigeren Startanimationen und […]

  45. […] un développeur qui a fait une grande partie du travail, expose de nombreux détails techniques sur son blog. Un certain nombre d’améliorations se traduisent par de meilleures fréquences […]

  46. […] der beschleunigten GNOME-Shell berichtete Entwickler Georges Stavracas bereits im Januar in seinem Blog. Er zählt eine Reihe von Verbesserungen auf, die zu verbesserten Bildraten, sanfteren […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.