Closed KeyboardDanni closed 4 years ago
Are you reading the data from a buffered source such as io::BufReader
? When reading from fs::File
directly, every sample read causes a system call, which would be slow. WavReader::open
uses a BufReader
by default.
If that is not the issue, you can try profiling with perf record
to see which operation is slow. If you compile with RUSTFLAGS=-g
, you get debug symbols (also when compiling in release mode) so perf report
can show symbol names.
Yeah, looks like the problem was that I wasn't buffering my file reads. Oops! WAV files load basically instantaneously now.
I don't use WavReader::open()
because I've abstracted out asset reading, so I needed something that takes a Reader
. The bug was in my code, so sorry for the noise!
Been attempting to diagnose performance-related issues with sound loading in my game engine. At first I assumed the culprit was the crate
audrey
's method of loading Ogg Vorbis data, since the iterator returned individual samples that all had to be unwrapped, instead of chunks of data. However, it turned out that the bottleneck was actually in loading the WAV files. I removedaudrey
from the equation and then reimplemented OGG and WAV loading using the base librarieslewton
andhound
. I did OGG first, then WAV. When I added WAV, I noticed that the loading times were just as slow.I converted all .WAV files to .OGG using
oggenc -q8
and now they load faster. I would expect that the .WAV files would be faster.This is on a system with plenty of free RAM, so disk I/O is not the culprit. The source files are also standard signed 16-bit PCM so I wouldn't expect the loading to take so long, but somehow it does.
How to reproduce:
WavReader::samples::<i16>()
oggenc -q8
on the .wav filelewton
exampleplayer
to play the .ogg file