-
Notifications
You must be signed in to change notification settings - Fork 154
Description
I'm using set_key_image to draw several animated keys on my Streamdeck V2, but the performance is quite poor. On the RPI Zero, it takes ~13ms to update one key, which means that I can't have very many keys animated without performance issues. I experimented a bit and the following changes would improve the speed:
- Instead of writing each 1kbyte packet to libhid, write the whole key. You would assemble a bytearray with the loop and then use a single call to libhid's write() to update the image. This cuts the time to update a key to ~4ms.
-I realize that the endpoint is only 1kbytes, so for this to work it relies on the transport layer or kernel driver to segment the transfer out again. On my system, the libhid call was the bottleneck for me, so there's a big improvement and no real downside.
- I can scale this up to support more keys per libhid call with minimal overhead. Looks like the limit is ~14 keys per call without performance tanking. My guess is there's some internal buffer in the streamdeck limiting this.
12keys = 13ms
13 keys = 14ms
14 keys = 15ms (86kbyte)
15 keys = 35ms (90kbyte)
To take advantage of this, I added a queue_key_image which just appends data to a bytearray and then a flush routine to apply everything. I don't know if this method will work on other models, but it does allow for 60fps smooth animations on the whole deck.
Would you like me to submit a PR with the changes? Or are there other issues where this wouldn't work generally?