Optimizing JS with Cinnamon
Cinnamon Javascript Optimization Techniques
This is a temporary chapter about Javascript optimization techniques in Cinnamon. It will be part of the dev guide when the Cinnamon design is described and the content of this section will then fit into the right place.
Notes
Some of these optimization techniques donโt make sense to us and we cannot explain them all, but they were tested methodically.
Jason is the only one in the team to see an impact from them. Heโs running a slow CPU with multi-monitors and a low-latency kernel with NVIDIA drivers. These were tested on Cinnamon 4.0. Performance boosts are witnessed in terms of input lag when moving windows and selecting text in Visual Studio Code.
These changes were tested in windowManager.js, an area of Cinnamon which is run constantly and which is prominent within the single execution thread.
Reducing the overal number of gsettings signal listeners
Hereโs an example: https://github.com/linuxmint/Cinnamon/commit/47bef00856e3b1f5a1e1a19e829dec498376d033
Reducing the number of listeners has a significant positive impact on performance.
Using declared functions in signal listeners
We found out that using:
was slower than:
i.e. declaring a function and referring to that function within the callback was faster than using an anonymous block of instructions in the callback.
The impact was significant.
Factorizing callbacks
was slower than:
It makes setProperty()
slower of course, although thatโs usually not critical, but it makes the overal project faster.
The impact wasnโt as significant and this optimization is probably only suited to critical paths such as windowmanager.js.
Grouping properties in smaller objects
Using this.smallobject.property
is faster than this.property
.
The idea is to avoid adding properties to large objects such as Main.wm.
So instead of using:
Main.wm.desktop_effects_enabled
, we use Main.wm.settings.desktop_effects_enabled
.
The impact is positive but subtle and this optimization is probably only suited to critical paths such as windowmanager.js.
Using hashmaps vs properties
Using this.smallobject['property']
is faster than this.smallobject.property
.
The idea is confirmed by https://jsperf.com/dot-notation-vs-square-bracket-notation.
So instead of using:
Main.wm.desktop_effects_enabled
, we use Main.wm.settings['desktop_effects_enabled']
.
The impact is positive but subtle and this optimization is probably only suited to critical paths such as windowmanager.js.
Last updated