You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems that having an unused where T in a function declaration can cause the function to become much slower and to allocate a lot more memory. Consider for example the following two functions which are identical except that the second one has an unnecessary where T:
function f1(x::Int)
return mod(2 * x + 1, 1000)
end
function f2(x::Int) where T # Note the unused `where T`
return mod(2 * x + 1, 1000)
end
Comparing performance of the two functions reveals that the second is much slower:
function test(f::Function)
x = 0
for i = 1:100000000
x = f(x)
end
x
end
test(f1)
@time test(f1) # 0.389844 seconds
test(f2)
@time test(f2) # 2.278735 seconds (96.00 M allocations: 1.431 GiB, 0.51% gc time)
Such unused where arguments can sometimes occur in large Julia codebases as leftovers from previous reversions, etc. In order to make sure they don't affect performance, perhaps we could consider either turning them into syntax errors or introduce an optimization pass that removes them automatically before compiling a function. See the following thread for more discussion https://discourse.julialang.org/t/unused-where-t-causes-a-function-to-become-very-slow/39727
The text was updated successfully, but these errors were encountered:
It seems that having an unused
where T
in a function declaration can cause the function to become much slower and to allocate a lot more memory. Consider for example the following two functions which are identical except that the second one has an unnecessarywhere T
:Comparing performance of the two functions reveals that the second is much slower:
Such unused
where
arguments can sometimes occur in large Julia codebases as leftovers from previous reversions, etc. In order to make sure they don't affect performance, perhaps we could consider either turning them into syntax errors or introduce an optimization pass that removes them automatically before compiling a function. See the following thread for more discussion https://discourse.julialang.org/t/unused-where-t-causes-a-function-to-become-very-slow/39727The text was updated successfully, but these errors were encountered: