Skip to content

opti audio stream function#149

Merged
teamclouday merged 3 commits into
teamclouday:mainfrom
wiiznokes:opti-stream-player
Apr 21, 2026
Merged

opti audio stream function#149
teamclouday merged 3 commits into
teamclouday:mainfrom
wiiznokes:opti-stream-player

Conversation

@wiiznokes
Copy link
Copy Markdown
Contributor

Avoid two allocation in the audio stream function

  • chunk is a wrapper over 2 slices (a view over the circular buffer), so we can use those instead of allocating a vector
    chunk
                            .into_iter()
                            .collect::<Vec<_>>()
                            .chunks_exact(std::mem::size_of::<F>())
  • we collect the sample in a buffer, and then write to the audio buffer. We can avoid this and directly write to the audio buffer

I've not benchmarked my changes tho

@wiiznokes
Copy link
Copy Markdown
Contributor Author

edit: i've added benchmarks

     Running benches\audio.rs (target\release\deps\audio-633b2ef21179e806.exe)
Gnuplot not found, using plotters backend
audio_processing        time:   [1.7843 µs 1.8321 µs 1.8847 µs]
                        change: [−43.366% −41.916% −40.626%] (p = 0.00 < 0.05)
                        Performance has improved.

     Running benches\audio.rs (target\release\deps\audio-633b2ef21179e806.exe)
Gnuplot not found, using plotters backend
audio_processing        time:   [3.2307 µs 3.2448 µs 3.2614 µs]
                        change: [+70.207% +73.747% +77.295%] (p = 0.00 < 0.05)
                        Performance has regressed.
Found 25 outliers among 100 measurements (25.00%)
  24 (24.00%) low severe
  1 (1.00%) high mild

above is with the optimization made in this patch, under is master, adapted to the test.
We can see a nice 50% performance boost!

@teamclouday
Copy link
Copy Markdown
Owner

Nice thanks for the optimization! Yes it makes sense the extra allocation is slow and unnecessary

@teamclouday teamclouday merged commit b137ecb into teamclouday:main Apr 21, 2026
4 checks passed
@wiiznokes wiiznokes deleted the opti-stream-player branch April 23, 2026 16:37
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

Successfully merging this pull request may close these issues.

2 participants