Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more efficient BUTTON_STATES #89

Open
maninalift opened this issue Oct 31, 2023 · 1 comment
Open

more efficient BUTTON_STATES #89

maninalift opened this issue Oct 31, 2023 · 1 comment

Comments

@maninalift
Copy link

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.

@alexmadeathing
Copy link

alexmadeathing commented Jan 2, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants