Bug 8204 - tl-startup-bg is very slow with high resolutions
Summary: tl-startup-bg is very slow with high resolutions
Status: NEW
Alias: None
Product: ThinLinc
Classification: Unclassified
Component: Other (show other bugs)
Version: trunk
Hardware: All All
: P2 Normal
Target Milestone: LowPrio
Assignee: Bugzilla mail exporter
Depends on:
Reported: 2023-08-15 17:04 CEST by Alexander Zeijlon
Modified: 2023-08-29 16:11 CEST (History)
1 user (show)

See Also:
Acceptance Criteria:

Performance profile and diff of modified code. (8.35 KB, text/plain)
2023-08-15 17:04 CEST, Alexander Zeijlon

Description Alexander Zeijlon cendio 2023-08-15 17:04:18 CEST
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.
Comment 1 Frida Flodin cendio 2023-08-29 16:11:37 CEST
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:

Note You need to log in before you can comment on or make changes to this bug.