dancasimiro / WAV.jl

Julia package for working with WAV files
Other
85 stars 35 forks source link

Slower loading because of GC issue #96

Open PallHaraldsson opened 3 years ago

PallHaraldsson commented 3 years ago

I tried (saving and) loading as in issue #52

and:

julia> @time y2, fs = wavread("test.wav");
  1.144121 seconds (564.27 k allocations: 223.779 MiB, 16.12% gc time, 76.35% compilation time)

julia> @time y2, fs = wavread("test.wav");
  0.156857 seconds (60 allocations: 190.738 MiB, 18.48% gc time)

julia> @time y2, fs = wavread("test.wav");
  0.232146 seconds (60 allocations: 190.738 MiB, 43.91% gc time)

julia> @time y2, fs = wavread("test.wav");
  0.143521 seconds (60 allocations: 190.738 MiB, 10.43% gc time)

a) The first load is slower (and precompiling can presumably be improved, I know about that, see recent blog post; for now only filing an issue so not forgotten).

b) After first run (no longer compilation overhead) still doesn't match Python:

a = time(); y, fs = read("test.wav"); time() - a
0.06549859046936035

Loading speed may not be to critical, but I assume this is not a constant factor (excepting first run overhead) and grows linearly with file size? Since it's seems to be a GC issue (at first I thought variable load on my machine) I think at least it's not an issue after loading (simply a memory buffer, and using/playing/accessing it shouldn't trigger GC?).

Do you hink it might be a simple issue to fix and/or memory mapping file could help? At least it's no longer "40 times slower" :) I'm on v"1.7.0-DEV.386", it was slightly faster than Julia 1.5.

julia> @time using WAV
  0.431934 seconds (433.26 k allocations: 28.546 MiB, 2.52% gc time, 1.76% compilation time)