swaywm / swaybg

Wallpaper tool for Wayland compositors
MIT License
490 stars 31 forks source link

Avoid setting dirty flag when nothing has changed #39

Closed bi4k8 closed 2 years ago

bi4k8 commented 2 years ago

I observed significant CPU usage from swaybg (mostly in various pixman functions) while testing an unrelated wlr-layer-shell client. It turned out that that client was calling zwlr_layer_surface_v1_set_size at ~1Hz, which is not an excessive rate, and each of these calls resulted in the compositor (sway 1.6-bebb726b, but also reproduced with another wlroots-based compositor) sending swaybg a zwlr_layer_surface_v1::configure event at the same frequency. swaybg unconditionally treats such events as dirtying and as such it was wasting a lot of CPU.

This PR just changes swaybg to only set its dirty flag when an event gives width/height/scale a value different from the last one observed for it.

I believe this would also have mitigated issues such as #33 and #38.

bi4k8 commented 2 years ago

Ah, it appears this is actually redundant with PR #30, which had not yet made it downstream to the Arch Linux repos. Never mind!