[PR #866] [MERGED] Improve dithering CPU usage #1119

Closed
opened 2026-02-27 20:01:14 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/librespot-org/librespot/pull/866
Author: @roderickvd
Created: 10/18/2021
Status: Merged
Merged: 10/19/2021
Merged by: @roderickvd

Base: devHead: dither-faster


📝 Commits (3)

  • 9ac52ba Improve dithering CPU usage
  • 12e5b98 Improve dithering CPU usage further on 64-bit platforms
  • 776b00e Improve dithering CPU usage further on 32-bit platforms

📊 Changes

4 files changed (+40 additions, -12 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 Cargo.lock (+12 -2)
📝 playback/Cargo.toml (+1 -0)
📝 playback/src/dither.rs (+26 -10)

📄 Description

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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/librespot-org/librespot/pull/866 **Author:** [@roderickvd](https://github.com/roderickvd) **Created:** 10/18/2021 **Status:** ✅ Merged **Merged:** 10/19/2021 **Merged by:** [@roderickvd](https://github.com/roderickvd) **Base:** `dev` ← **Head:** `dither-faster` --- ### 📝 Commits (3) - [`9ac52ba`](https://github.com/librespot-org/librespot/commit/9ac52ba9dd48c7a1520c7b8739d259d9988949dd) Improve dithering CPU usage - [`12e5b98`](https://github.com/librespot-org/librespot/commit/12e5b9883513fdcb63a64ce2fa62b9d4402d55de) Improve dithering CPU usage further on 64-bit platforms - [`776b00e`](https://github.com/librespot-org/librespot/commit/776b00e5dafc64a781ed409f9870fba2c49acc4a) Improve dithering CPU usage further on 32-bit platforms ### 📊 Changes **4 files changed** (+40 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `Cargo.lock` (+12 -2) 📝 `playback/Cargo.toml` (+1 -0) 📝 `playback/src/dither.rs` (+26 -10) </details> ### 📄 Description 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`](https://docs.rs/rand/0.8.4/rand/rngs/struct.SmallRng.html) 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`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 20:01:14 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/librespot#1119
No description provided.