jump-dev / HiGHS.jl

A Julia interface to the HiGHS solver
https://highs.dev
MIT License
103 stars 14 forks source link

performance issue #115

Closed 1991jhf closed 2 years ago

1991jhf commented 2 years ago

Hi, I noticed adding variables for HiGHS solver is very slow compare to cplex solver. It seems there is a lot of allocations going on. Below is the code:

using HiGHS using CPLEX import MathOptInterface as MOI

highs_model=HiGHS.Optimizer() cplex_model=CPLEX.Optimizer()

@time MOI.add_variables(highs_model,100000) 1.811086 seconds (100.01 k allocations: 8.694 MiB, 7.26% gc time)

@time MOI.add_variables(cplex_model,100000) 0.011854 seconds (400.01 k allocations: 15.561 MiB)

odow commented 2 years ago

It actually seems like there are less allocations in HiGHS?

Is adding variables a bottleneck in a real use-case?

odow commented 2 years ago

This isn't overhead in HiGHS.jl, it's the cost in the underlying solver:

julia> import HiGHS

julia> const MOI = HiGHS.MOI
MathOptInterface

julia> function main(N)
           highs = HiGHS.Optimizer()
           MOI.add_variables(highs, N)
           return highs
       end
main (generic function with 1 method)

julia> @time main(10_000)
  0.026619 seconds (10.04 k allocations: 962.594 KiB)
A HiGHS model with 10000 columns and 0 rows.

julia> @time main(100_000)
  1.644493 seconds (100.05 k allocations: 8.870 MiB)
A HiGHS model with 100000 columns and 0 rows.

julia> function bar(N)
           highs = HiGHS.Highs_create()
           for _ in 1:N
               HiGHS.Highs_addCol(highs, 0.0, -Inf, Inf, 0, C_NULL, C_NULL)
           end
           HiGHS.Highs_destroy(highs)
           return
       end
bar (generic function with 1 method)

julia> @time bar(10_000)
  0.023322 seconds

julia> @time bar(100_000)
  1.671258 seconds
1991jhf commented 2 years ago

Thank you for digging into the issue. It is common in my use case to add millions of variables and constraints. It is quiet fast in 1.0.0. I will report to HiGHS team.

odow commented 2 years ago

It is quiet fast in 1.0.0

In HiGHS.jl v1.0.0 or HiGHS the solver?

odow commented 2 years ago

I will report to HiGHS team.

I can do it. I'm just testing some different things

odow commented 2 years ago

Closing in favor of https://github.com/ERGO-Code/HiGHS/issues/830