You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
You're right that it would be more efficient to store using a bitfield, but hash maps are not slow. They're not as fast as random access to an array, but they're also not something to worry too much about for a library like this where the events are infrequent. You could throw together a PR if you think you can implement it without too much added complexity. @obv-mikhail is responsive and reads all new PRs.
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.
The text was updated successfully, but these errors were encountered: