Bevy wasm audio performance issues
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## Bevy version and features
Tested on 0.18.0 , bevy_audio
## What
Bevy_audio has very bad performance in wasm builds. On each frame it creates new JS listeners which eventually are causing very heavy GC runs which can drop several frames. It happens every few seconds. Issue occurs even for very simple example like: [https://bevy.org/examples/audio/audio/)](https://bevy.org/examples/audio/audio/)
It also might cause issues like choppy sound, freezing etc.
example screenshots:
## Additional information
From my initial investigation root cause it's not bevy but `cpal` library which is used in bevy_audio or other audio plugins like bevy_kira_audio.
Also mentioned issue: https://github.com/RustAudio/cpal/issues/780
## My workaround
Personally I made very primitive plugin which directly works with JS api and it works much better not causing heavy GC's
Contributor guide
Research direction
Start by reproducing the issue with the linked Bevy audio example in a wasm build and inspect the reported cpal issue for the suspected cause. Compare listener and garbage-collection behavior with the provided workaround. Done means wasm audio no longer creates recurring heavy GC pauses, frame drops, choppy sound, or freezing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, wasm
- Domain
- audio-video-rtc, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100