python-mss icon indicating copy to clipboard operation
python-mss copied to clipboard

Improve speed on GNU/Linux with XShm

Open BoboTiG opened this issue 6 years ago • 8 comments

XShm seems a good use for improving speed on GNU/Linux.

See https://stackoverflow.com/a/43500537/1117028 for a idea of implementation.

We could also find valuable information here: http://www.rahul.net/kenton/perf.html

The goal is to let MSS find the best implementation to use at initialization

BoboTiG avatar Jan 29 '19 22:01 BoboTiG

Any update on this? Would be nice to run a quick comparison to see if there's a real benefit. Currently on Ubuntu.

Murplugg avatar Feb 02 '21 03:02 Murplugg

Found an SO comment on how using XShmGetImage can be faster than XGetImage, maybe worth a read: https://stackoverflow.com/questions/30200689/perfomance-of-xgetimage-xputimage-vs-xcopyarea-vs-xshmgetimage-xshmputima#comment79301257_30200689

Quoted:

you should use XShmGetImage+XShmPutImage. With XGetImage, your program will allocate memory and receive the image data from the X server through the X server pipe. As you've seen you have to XFree() the allocated memory every time. With XShmGetImage+XShmPutImage you pre-allocate a shared memory region that will be used every time you call XShmGetImage, so you don't need to allocate+free every time. Plus since the memory is shared, the X server simply copies the image data to the memory you allocated, no need to send the data through the pipe.

Murplugg avatar Feb 02 '21 17:02 Murplugg

That would be a great improvement, indeed. I am just lacking of time and motivation. But since you are in need for that feature, I will be able to work on it. It will not be for tomorrow though ;)

BoboTiG avatar Feb 02 '21 17:02 BoboTiG

Of course, if you want to give a try, it would be awesome :)

BoboTiG avatar Feb 02 '21 17:02 BoboTiG

That's alright, no stress. It could be a good nice to have is all, MSS already is pretty performant. I too lack time, maybe not motivation but definitely the skill to walk the walk lol.

Murplugg avatar Feb 13 '21 16:02 Murplugg

Hi, I am interested as well !

pporcher avatar Aug 01 '21 10:08 pporcher

Seems the 2nd URL in the OP is down. Wayback machine has it at https://web.archive.org/web/20191107002534/http://www.rahul.net/kenton/perf.html.

Murplugg avatar Jun 02 '22 00:06 Murplugg