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

Improve dithering CPU usage #866

Merged
merged 3 commits into from
Oct 19, 2021
Merged

Conversation

roderickvd
Copy link
Member

@roderickvd roderickvd commented Oct 18, 2021

This little PR shaves off about 33% CPU usage when dithering, while the effects on the binary size are next to none. This is true both on my Raspberry Pi 3B+ (from about 15 to 10% CPU) and my Mac (from 3 to 1%).

The trick is taking cue from SmallRng instead of ThreadRng, then sprinkling some 64-bit optimisations on top by hand-picking the fastest generator that still has high enough linear complexity for 64-bit floats.

SmallRng may be a good choice when a PRNG with small state, cheap initialization, good statistical quality and good performance are required. [...] The PRNG algorithm in SmallRng is chosen to be efficient on the current platform, without consideration for cryptography or security.

While at it, bump the rand_distr crate, even though it doesn't contribute to the speed-up.

Unless there are any objections, I intend to merge this before releasing 0.3.1.

@roderickvd roderickvd merged commit 4c89a72 into librespot-org:dev Oct 19, 2021
@roderickvd roderickvd deleted the dither-faster branch October 19, 2021 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant