Concrete optimizer type in CachingOptimizer #2520
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Here are benchmarks (the timing vary quite a lot depending on the % of GC time) so it's more interesting to look at allocations:
Before:
After:
With
Before:
After:
The big allocation drop here from
1.3 M
to200 k
is due to https://github.com/jump-dev/JuMP.jl/blob/master/src/variables.jl#L882-L908 where we use the backend like it's type stable but before this PR, the caching optimizer isMOIU.CachingOptimizer{MOI.AbstractOptimizer}
and after this PR, it isMOI.CachingOptimizer{MOIU.MockOptimizer{MOIU.Model{Float64}}}
.As the
backend
type is not concrete, it seems wasteful to also have a non-concrete optimizer type in the optimizer field of the backend.We can benefit from the non-concretess of the backend in
set_optimizer
by changing its type.Another option would be to parametrize the
JuMP.Model
type by the backend type and have a non-concrete optimizer type for the optimizer of the caching optimizer.We need at least one to be an abstract type so that we can implement
set_optimizer
but it seems wasteful to have both of them.Note that with this PR, we have less allocation once we set the optimizer even if it's empty as the non-concreteness of the optimizer gives allocations even if it is not used it seems.