-
Notifications
You must be signed in to change notification settings - Fork 87
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
Fix inference issue in MOIU.Model #1256
Conversation
And proof from the original JuMP issue: #1255. julia> @btime plain(1_000_000);
99.679 ms (2000244 allocations: 142.09 MiB)
julia> @btime with_int_and_bounds(1_000_000);
117.368 ms (2000244 allocations: 142.09 MiB) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
This is awesome! However I don't quite understand what's happening. In both case there is the type unstability but in both cases we do not run the type unstable code. In the first case, the type unstable code is inside an
The inference of which type ? The type of |
oops. I didn't update the head of the PR. My original solution (annotating with |
Here's what happens now: julia> model = MOIU.Model{Float64}()
MOIU.Model{Float64}
julia> x = MOI.add_variable(model)
MathOptInterface.VariableIndex(1)
julia> @code_warntype MOIU.throw_if_upper_bound_set(x, MOI.LessThan{Float64}, 0x0, Float64)
Variables
#self#::Core.Compiler.Const(MathOptInterface.Utilities.throw_if_upper_bound_set, false)
variable::MathOptInterface.VariableIndex
S2::Core.Compiler.Const(MathOptInterface.LessThan{Float64}, false)
mask::UInt8
T::Core.Compiler.Const(Float64, false)
upper_mask::UInt8
Body::Nothing
1 ─ (upper_mask = mask & MathOptInterface.Utilities.UPPER_BOUND_MASK)
│ %2 = MathOptInterface.Utilities.iszero(upper_mask)::Bool
└── goto #3 if not %2
2 ─ return
3 ─ %5 = MathOptInterface.Utilities.single_variable_flag(S2)::Core.Compiler.Const(0x04, false)
│ %6 = (%5 & MathOptInterface.Utilities.UPPER_BOUND_MASK)::Core.Compiler.Const(0x04, false)
│ %7 = MathOptInterface.Utilities.iszero(%6)::Core.Compiler.Const(false, false)
└── goto #5 if not %7
4 ─ Core.Compiler.Const(:(return), false)
5 ┄ MathOptInterface.Utilities._throw_if_upper_bound_set(variable, S2, upper_mask, T)
└── Core.Compiler.Const(:(return %10), false) The |
That makes more sense. Is there a way to avoid the function being inlined? It's not being inlined now but it might be in a future Julia version |
My guess is that Julia would only inline if it infers nicely. I don't think we need to do anything explicitly here. It's something we can check in a future release. |
If it stops inferring we won't notice as we have no tests. We could use |
Closes #1255
Before
After