KunalBagaria / rustyvibes

A Rust CLI that makes mechanical keyboard sound effects on every key press
https://github.com/kunalbagaria/rustyvibes
MIT License
208 stars 26 forks source link

Improve latency and reduce memory usage #10

Closed binarybana closed 2 years ago

binarybana commented 2 years ago

By using a threadpool, we can reduce thread startup times (minimal impact) and more importantly: cache rodio OutputStream creation which costs about 10-20ms per keypress. And all around reduce allocation.

We also cache file reading in a global hashmap.

Ironically, this caching seems to reduce memory usage in my testing (MacOSX looking at private and total).

KunalBagaria commented 2 years ago

Thanks a lot for taking the time to improve this repository, appreciate it 😄

KunalBagaria commented 2 years ago

I just noticed this, this is causing a lot more idle CPU usage, would you know what would be causing that?

KunalBagaria commented 2 years ago

I have made a branch where sink and caching has been implemented but the thread pooling has been reversed: https://github.com/kb24x7/rustyvibes/tree/revert-10-jk/optimize

KunalBagaria commented 2 years ago

I have merged this branch, please create a new PR if you find any fix, thanks