Skip to content

Conversation

joaquimg
Copy link
Member

These were no help at all, on the contrary.

Before:

julia> main()
typeof(keys(d)) = Vector{MathOptInterface.VariableIndex}
  0.361756 seconds (2 allocations: 762.939 MiB, 19.29% gc time)
  0.064835 seconds

After:

julia> main()
typeof(keys(d)) = Base.KeySet{MathOptInterface.VariableIndex, MathOptInterface.Utilities.CleverDicts.CleverDict{MathOptInterface.VariableIndex, Int64, typeof(MathOptInterface.Utilities.CleverDicts.key_to_index), typeof(MathOptInterface.Utilities.CleverDicts.index_to_key)}}
  0.032200 seconds
  0.062263 seconds

Code:

using MathOptInterface

const CleverDicts = MathOptInterface.Utilities.CleverDicts

function build(N::Int)
    d = CleverDicts.CleverDict{MathOptInterface.VariableIndex, Int}()
    for i in 1:N
        CleverDicts.add_item(d, i)
    end
    return d
end

function test2_k(d, N)
    val = 0
    for k in keys(d)
        val += k.value
    end
    @assert val == N*(N+1)/ 2 #sum(1:N)
end

function test2_v(d, N)
    val = 0
    for v in values(d)
        val += v
    end
    @assert val == N*(N+1)/ 2 #sum(1:N)
end

function main()
    N = 100_000_000
    d = build(N)

    @show typeof(keys(d))

    @time test2_k(d, N)
    @time test2_v(d, N)

end

main()

@@ -154,7 +154,7 @@ function MOI.get(
v::VectorOfConstraints{F,S},
::MOI.ListOfConstraintIndices{F,S},
) where {F,S}
return keys(v.constraints)
return collect(keys(v.constraints))
Copy link
Member

Choose a reason for hiding this comment

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

So I guess the issue was that we were returning the concrete list of keys, instead of a lazy evaluator?

Copy link
Member Author

Choose a reason for hiding this comment

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

exactly!

Copy link
Member

@odow odow left a comment

Choose a reason for hiding this comment

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

I'm all for removing complexity.

@odow odow merged commit 70c7a1b into master Nov 20, 2022
@odow odow deleted the jg/cvit branch November 20, 2022 23:52
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