-
-
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 for simple bisection function #42007
Comments
Looks regressed in 1.7-beta already. The performance difference goes away if the call is made type stable: |
Ugh, that's an excellent point. I thought about type-instability because of the unexpected memory allocations, I completely overlooked the fact the input arguments were reused in the body of the function, but I did use julia> @code_warntype bisectroot(x -> x^2-7, 0, 7)
MethodInstance for bisectroot(::var"#19#20", ::Int64, ::Int64)
from bisectroot(f::Function, left, right) in Main at /tmp/foo.jl:1
Arguments
#self#::Core.Const(bisectroot)
f::Core.Const(var"#19#20"())
left::Int64
right::Int64
Body::Float64
1 ─ %1 = (#self#)(f, left, right, 1.0e-6)::Float64
└── return %1 A type-unstable call is probably borderline in terms of what's expected to be optimised, right? |
I'm certainly curious to find out what caused this. |
It's because of the default argument. Use cthulhu to dig deeper into the calls. |
On 1.6, inference gives |
Bisected:
vs
cc @tkf |
The tmerge here is a slightly odd. While true it is exactly equal to the Union of the 2 input types, it is an awkward way to express the 3 Tuple elements, and so the optimizer later struggles to split this well in SROA.
This means codegen sees this type: |
on v1.6:
on
master
(a11de31):Note that on
master
the function allocates, when it shouldn't.The regression can be completely cleared (
master
would be actually ~25% faster) by replacingleft, right = f(mid) > 0 ? (left, mid) : (mid, right)
with anif
like this:v1.6:
master
:At the moment I can't run git bisect myself to try and find the culprit (would take too long...), but if someone has clues about potential candidates, I could do a smaller search.
The text was updated successfully, but these errors were encountered: