-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Large performance regression in trunc with vector argument #19849
Comments
There have been previous performance regressions when using types as arguments to functions. They got fixed by explicitly specializing on the type, i.e |
There is an ugly workaround: julia> @benchmark trunc.(Int, $array)
BenchmarkTools.Trial:
samples: 10000
evals/sample: 1
time tolerance: 5.00%
memory tolerance: 1.00%
memory estimate: 23.75 kb
allocs estimate: 1008
minimum time: 380.08 μs (0.00% GC)
median time: 428.49 μs (0.00% GC)
mean time: 452.06 μs (0.44% GC)
maximum time: 16.49 ms (0.00% GC)
julia> @benchmark (x->trunc(Int, x)).($array)
BenchmarkTools.Trial:
samples: 10000
evals/sample: 8
time tolerance: 5.00%
memory tolerance: 1.00%
memory estimate: 8.00 kb
allocs estimate: 1
minimum time: 3.28 μs (0.00% GC)
median time: 4.37 μs (0.00% GC)
mean time: 5.13 μs (3.22% GC)
maximum time: 2.01 ms (0.00% GC) |
I have the following theory for the cause of the problem: |
cc @pabloferz as well, if you have any ideas |
Maybe we need something like |
This performance issue and this #19421 (comment) have the same root cause. I already had an idea on how to fix it, will submit a PR. |
After #19791, the manually vectorized method of
trunc
is deprecated and the dot syntax should be used. However, the 2-arg method is now much slower than before.I've a function where this regression is sensible, even if
trunc(Int, array)
is a relatively small part of computation and profiling confirms that broadcastingtrunc
takes a while.Before the PR (manually vectorized method):
after the PR (dot syntax):
Now
trunc.(Int, array)
is 100× slower than the oldtrunc(Int, array)
and more memory-eager.@code_warntype trunc.(Int, array)
indicates that the returned value is type-stable, but there are type-unstable variables inside the function.Note that the current
trunc.(array)
is comparable to the oldtrunc(Int, array)
.Edit: for comparison, these are the results of benchmark in Julia 0.5:
trunc.(array)
was already faster thantrunc(array)
and now it's even better, the problem is the method with a type argument.The text was updated successfully, but these errors were encountered: