Skip to content
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

Performance improvements in linear_terms and quad_terms #1604

Merged
merged 2 commits into from
Nov 13, 2018
Merged

Conversation

mlubin
Copy link
Member

@mlubin mlubin commented Nov 11, 2018

Ref https://discourse.julialang.org/t/allocations-when-manipulating-an-iterator/17405 and #1403 (comment).

I see a 5x speedup in JuMP.moi_function(::AffExpr) and a 3.3x speedup in JuMP.moi_function(::QuadExpr). This removes 4 of 10 allocations per term in the minipmed example (#1403 (comment)).
Before:

0.656219 seconds (5.00 M allocations: 568.758 MiB, 37.93% gc time)

After:

0.564028 seconds (3.00 M allocations: 507.723 MiB, 30.32% gc time)

There are still 6 more allocations per term to track down before we can (hopefully) get back to 0.18's performance.

@mlubin mlubin changed the title ⚡ Performance improvements in linear_terms and quad_terms Performance improvements in linear_terms and quad_terms Nov 11, 2018
@codecov
Copy link

codecov bot commented Nov 11, 2018

Codecov Report

Merging #1604 into master will increase coverage by 0.16%.
The diff coverage is 80%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1604      +/-   ##
==========================================
+ Coverage    90.8%   90.96%   +0.16%     
==========================================
  Files          28       28              
  Lines        3708     4062     +354     
==========================================
+ Hits         3367     3695     +328     
- Misses        341      367      +26
Impacted Files Coverage Δ
src/quad_expr.jl 91.01% <80%> (-0.46%) ⬇️
src/aff_expr.jl 94.78% <80%> (+0.28%) ⬆️
src/Derivatives/forward.jl 94.1% <0%> (-0.11%) ⬇️
src/JuMPArray.jl 72.77% <0%> (+1.34%) ⬆️
src/macros.jl 91.59% <0%> (+2.1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 67133a8...9c8b011. Read the comment docs.

src/quad_expr.jl Outdated
@@ -112,15 +112,31 @@ if VERSION < v"0.7-"
Base.done(qti::QuadTermIterator, state::Int) = done(qti.quad.terms, state)
Base.next(qti::QuadTermIterator, state::Int) = reorder_iterator(next(qti.quad.terms, state)...)
else
function reorder_iterator(t::Tuple{Pair{<:UnorderedPair,<:Any},Int})
((first(t).second, first(t).first.a, first(t).first.b), last(t))
function reorder_and_flatten(p::Pair{<:UnorderedPair,<:Any})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pair{<:UnorderedPair,<:Any} is equivalent to Pair{<:UnorderedPair} which is arguably simpler/more readable

@mlubin mlubin merged commit a0af39d into master Nov 13, 2018
@mlubin mlubin deleted the ml/faster branch November 13, 2018 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants