dancasimiro / WAV.jl

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

A couple of performance improvements #67

Closed rdeits closed 6 years ago

rdeits commented 6 years ago

I found a couple of low-hanging fruit for improving the performance of reading WAV files:

  1. use ::Type{T} where T instead of just T as an argument to ensure Julia specializes on that type
  2. Access the samples array in column-major order
  3. Add @inbounds

More improvements should be possible, but this already gave a better than 10x speedup, so I figured I'd open a PR.

Before (on Julia 0.7), using the test file from https://github.com/dancasimiro/WAV.jl/issues/52 :

julia> using BenchmarkTools, WAV
julia> y = sin.((0:9999999)/48000*2pi*440);

julia> wavwrite(y, "test.wav", Fs=48000)

julia> @btime wavread("test.wav")
  4.597 s (29999537 allocations: 572.20 MiB)

after:

julia> @btime wavread("test.wav")
  321.458 ms (10000049 allocations: 305.18 MiB)

Completely fixing #52 is almost certainly possible, but would probably require something like https://github.com/tkoolen/FastIOBuffers.jl to speed up reading Float32s from IO streams.

coveralls commented 6 years ago

Coverage Status

Coverage remained the same at 72.535% when pulling 952862f1ff99240240787c9c8831d891c921c040 on rdeits:rd/performance into 0869a0cd407f6724a95255ccdb61b0c8c38f17cd on dancasimiro:master.

dancasimiro commented 6 years ago

thanks @rdeits