JuMP.set_objective_coefficient performance

Hi, I’m using JuMP to build LP-problems and later I want to update the objective coefficients with the function set_objective_coefficient instead of building the whole LP again. Below are the functions I defined and the time it took to run them. They seem to be slow. Please help me make the code faster.

function BuildFull(Big::Float64)::JuMP.Model

   M = Model(with_optimizer(CPLEX.Optimizer))
   NArea = 57
   NMod = 20
   NKOpt = 168
   InfUB = 1.0E8

   @variable(M,0.0 <= spi[iArea=1:NArea,iMod=1:NMod,k=1:NKOpt] <= InfUB, base_name="spi")
   @objective(M,MathOptInterface.MIN_SENSE, sum(spi[iArea,iMod,k] for iArea=1:NArea for iMod=1:NMod for k=1:NKOpt)) 

   return M

function update_coeff!(model::JuMP.Model)
     iMod = 1
     spi = model[:spi]
	  for iArea=1:NArea
        for k=1:NKOpt
		      spi_coeff = 2.0
		      set_objective_coefficient(model, spi[iArea,iMod,k], spi_coeff)
	  return nothing


I time the functions with the @time macro

using JuMP
using CPLEX
using MathOptFormat
using MathOptInterface
const MOI = MathOptInterface

const Big = 1.0E18

model = @time BuildFull(Big)
@time update_coeff!(model)

The @time macro returns the following:
0.575319 seconds (2.38 M allocations: 127.048 MiB, 51.21% gc time)
20.401694 seconds (94.43 k allocations: 27.333 GiB, 20.58% gc time)

This is the second run. 20 seconds seems a long time.
Is it possible to speed things up?
Tips to increase performance of @variable is also appreciated.

These are the package versions I use:

julia> Pkg.installed()
Dict{String,Union{Nothing, VersionNumber}} with 14 entries:
  "Distributions"    => v"0.24.3"
  "Clp"              => v"0.8.3"
  "Atom"             => v"0.12.25"
  "CPLEX"            => v"0.6.2"
  "JuMP"             => v"0.20.1"
  "Juno"             => v"0.8.4"
  "DelimitedFiles"   => nothing
  "MathOptFormat"    => v"0.4.0"
  "StatsBase"        => v"0.33.2"
  "HDF5"             => v"0.12.5"
  "Plots"            => v"1.4.3"
  "Cbc"              => v"0.7.1"
  "MathOptInterface" => v"0.9.8"
  "Printf"           => nothing

A simple speed-up option is to iterate over columns instead of rows in multi-dimensional arrays (as stated in the Julia performance tips). Thus in function update_coeff! do

for k=1:NKOpt
   for iArea=1:NArea        
		spi_coeff = 2.0
	    set_objective_coefficient(model, spi[iArea,iMod,k], spi_coeff)

But this is still slower that re-building the model (at least on my machine). I get

0.253191 seconds (2.30 M allocations: 125.016 MiB)
4.129311 seconds (38.30 k allocations: 27.330 GiB, 4.25% gc time).

JuMP seems to allocate a lot of memory for the set_objective_coefficient function.

Thanks, mike_k. Good point.

However, changing to iterate over columns hardly makes any difference here.
I get :

  0.551281 seconds (2.38 M allocations: 127.002 MiB, 43.35% gc time)
 19.040779 seconds (94.42 k allocations: 27.333 GiB, 14.91% gc time)

I see I have more gc time.
Are yoiu on the same JuMP version as I? JuMP 0.20.1

Interesting, the exchange I suggested reduced the runtime by 50% on my machine. I am using JuMP 0.21.2