Created attachment 1154 [details]
Performance profile and diff of modified code.
It looks like the python implementation of xlib, that we use for drawing a background image in the profile chooser at session start, does not scale well with higher (e.g. UHD) resolutions, especially if there is more than one monitor present.
Computing and setting the background image takes somewhere between 10 and 14 seconds on my machine, where one could expect this change to be nearly instant.
This suboptimal performance is likely due to the fact that xlib is fully implemented in python, and we should maybe look for an alternative solution, e.g. one that uses a faster language like C under the surface.
The modified code for performance measurement and the performance profile can both be seen in the attached file. The profile shows measurements for computing and setting a background on two monitors in full screen where they have the following resolutions:
* Monitor 1: 1920x1200
* Monitor 2: 3840x2160
Note that in the flush-calls seen in the performance profile forces the implementation to handle all queued requests, which in turn requires each request to be converted from a python object to a byte-string before it can be passed over a socket to the Xserver.
Another way forward could be to use shared memory with the Xserver instead of passing the image data over the socket.
There is an X extension for shared memory named MIT-SHM (The MIT Shared Memory Extension). However, this is not implemented in the Python xlib we use, so this would need for us to first extend python xlib to be able to use this.
TigerVNC implements shared memory for the pixel buffer. Here is the function that sets up the shared memory. This could be used as a guide if we want to try this for this bug: