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

Improve performance of MOI.copy_to #203

Merged
merged 1 commit into from
Dec 13, 2021
Merged

Improve performance of MOI.copy_to #203

merged 1 commit into from
Dec 13, 2021

Conversation

odow
Copy link
Member

@odow odow commented Dec 13, 2021

Part of jump-dev/JuMP.jl#2817

If we include jump-dev/MathOptInterface.jl#1704

Script

using MathOptInterface
const MOI = MathOptInterface
using GLPK

function create_model(I, T = 10000)
    model = MOI.Utilities.Model{Float64}()
    v = MOI.VariableIndex[]
    for _ in 1:I
        x = MOI.add_variables(model, T)
        MOI.add_constraint.(model, x, MOI.GreaterThan(0.0))
        MOI.add_constraint.(model, x, MOI.LessThan(100.0))
        for t in 2:T
            f = MOI.ScalarAffineFunction(
                MOI.ScalarAffineTerm.([1.0, -1.0], [x[t], x[t-1]]),
                0.0,
            )
            MOI.add_constraint(model, f, MOI.GreaterThan(-10.0))
            MOI.add_constraint(model, f, MOI.LessThan(10.0))
        end
        append!(v, x)
    end
    g = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(1.0, v), 0.0)
    MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
    MOI.set(model, MOI.ObjectiveFunction{typeof(g)}(), g)
    dest = GLPK.Optimizer()
    MOI.copy_to(dest, model)
    return dest
end

Before

julia> @benchmark create_model(100, 1000)
BenchmarkTools.Trial: 11 samples with 1 evaluation.
 Range (min  max):  348.692 ms  690.298 ms  ┊ GC (min  max): 23.52%  55.39%
 Time  (median):     468.977 ms               ┊ GC (median):    34.47%
 Time  (mean ± σ):   510.078 ms ± 141.469 ms  ┊ GC (mean ± σ):  44.43% ± 15.48%

  ▁  ▁ █   ▁           ▁                           █    ▁  ▁  ▁  
  █▁▁█▁█▁▁▁█▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁█▁▁█▁▁█ ▁
  349 ms           Histogram: frequency by time          690 ms <

 Memory estimate: 384.43 MiB, allocs estimate: 2898897.

After

julia> @benchmark create_model(100, 1000)
BenchmarkTools.Trial: 20 samples with 1 evaluation.
 Range (min  max):  184.094 ms  390.970 ms  ┊ GC (min  max): 12.39%  19.73%
 Time  (median):     240.240 ms               ┊ GC (median):    24.33%
 Time  (mean ± σ):   253.573 ms ±  43.221 ms  ┊ GC (mean ± σ):  24.21% ±  5.05%

                ▃██       ▃  ▃                                   
  ▇▁▁▁▁▁▁▁▁▁▇▁▇▇███▁▁▇▇▁▁▁█▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▇▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▇ ▁
  184 ms           Histogram: frequency by time          391 ms <

 Memory estimate: 152.62 MiB, allocs estimate: 1299738.

@codecov
Copy link

codecov bot commented Dec 13, 2021

Codecov Report

Merging #203 (189de8c) into master (aaca5ba) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #203      +/-   ##
==========================================
- Coverage   82.85%   82.84%   -0.01%     
==========================================
  Files           9        9              
  Lines        1761     1760       -1     
==========================================
- Hits         1459     1458       -1     
  Misses        302      302              
Impacted Files Coverage Δ
src/MOI_wrapper/MOI_copy.jl 97.08% <100.00%> (-0.03%) ⬇️

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 aaca5ba...189de8c. Read the comment docs.

@odow odow merged commit 485c89e into master Dec 13, 2021
@odow odow deleted the od/moi-perf branch December 13, 2021 19:53
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.

1 participant