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
Setting names is very slow, does a lot of work, some of it redundant #452
Comments
The code here does a hash and lookup on the name 3 times if I'm counting correctly between the Also is this string always constructed or only if the error case hits? |
More tests - commenting out the checks actually doesn't affect run time much - rather, the two lines of storing stuff does. |
We're also missing |
struct VariableIndex
value::Int64
end
Base.hash(index::VariableIndex, h::UInt) = hash(index.value, h)
const NAMES = String[string("vars", "[", i, "]") for i in 1:10^6]
function run_moi_str_test()
model = VariableIndex[]
varnames = Dict{VariableIndex, String}()
namesvar = Dict{String, VariableIndex}()
for i in 1:10^6
vi = VariableIndex(i)
push!(model, vi)
name = string("vars", "[", i, "]")
varnames[vi] = name
namesvar[name] = vi
end
end
|
Does |
When you delete variables, there will be holes, how do you handle that ? |
I suppose either a |
We will need to benchmark name = vec[index]
if name === nothing
throw(MOI.InvalidIndex(index))
end
return name::String against if haskey(cardinal_dict, index)
throw(MOI.InvalidIndex(index))
end
return cardinal_dict[index] |
Closing because all the bottleneck is setting the name in the dict here: MathOptInterface.jl/src/Utilities/model.jl Lines 353 to 355 in f49fde0
function run_test()
model = JuMP.Model()
JuMP.@variable(model, vars[1:10^6])
return model
end
run_test()
Profile.init(n=Int(1e8), delay=0.00000001)
@pprof run_test() But even adding a million variables only takes 0.5 seconds. julia> @time run_test();
0.583714 seconds (6.00 M allocations: 344.590 MiB) There are bigger fish to fry. |
In particular, the code here:
jump-dev/JuMP.jl#1402 (comment)
stress tests the
setname
logic and shows it allocates quite a bit, and takes a lot of time.The text was updated successfully, but these errors were encountered: