InputBot icon indicating copy to clipboard operation
InputBot copied to clipboard

more efficient BUTTON_STATES

Open maninalift opened this issue 8 months ago • 1 comments

I noticed that BUTTON_STATES is a hash-map wrapped in a mutex.

I'm a total Rust beginner so this may be naive.

Hash maps are slow, and here we are just storing binary values for a known set of keys so I thought it would be possible to store them as a simple array of bits.

If we are limited to 256 keycodes, then this seems very doable.

If we are just setting and reading individual bits from an array, it should be possible to do atomically removing the need for a mutex.

I had a quick search and it seems like the bitvec library in fact uses atomic operations by default.

It looks like there are not many places that would need to be changed. As I have also said in the other issue I raised today, I'm not sure whether this library is actively maintained, bit of it is then I'll have a look into this.

maninalift avatar Oct 31 '23 14:10 maninalift