Maybe I should post an issue on the package site, but lets go. Given this simple threaded loop:
julia> using ProgressMeter, BenchmarkTools
julia> function loop(n)
s = zeros(Threads.nthreads())
Threads.@threads for i in 1:n
s[Threads.threadid()] += sin(i)
end
sum(s)
end
loop (generic function with 1 method)
julia> @btime loop(1000000)
4.401 ms (22 allocations: 1.97 KiB)
-0.1171095240981539
Now if I add a progress meter, even if it is disabled, I get:
julia> function loop(n)
p = Progress(n,dt=0.1,enabled=false)
s = zeros(Threads.nthreads())
Threads.@threads for i in 1:n
s[Threads.threadid()] += sin(i)
next!(p)
end
sum(s)
end
loop (generic function with 1 method)
julia> @btime loop(1000000)
435.372 ms (369003 allocations: 11.26 MiB)
-0.1171095240981539
Thus, I get lots of allocations, and the overhead is also very large, considering that with it disabled I imagine that it should only return from next!
without doing nothing.
I can even add this simple mynext!
function to check if the progress meter is enabled, to get a much better result:
julia> function mynext!(p::Progress)
if p.enabled
next!(p)
end
nothing
end
mynext! (generic function with 1 method)
julia> function loop(n)
p = Progress(n,dt=0.1,enabled=false)
s = zeros(Threads.nthreads())
Threads.@threads for i in 1:n
s[Threads.threadid()] += sin(i)
mynext!(p)
end
sum(s)
end
loop (generic function with 1 method)
julia> @btime loop(1000000)
5.521 ms (31 allocations: 2.50 KiB)
-0.1171095240981539
I am doing something wrong, or should I just post an issue?
Thanks.