Skip to content

Improve performance of values_as_in_model #986

@penelopeysm

Description

@penelopeysm

Right now values_as_in_model always re-evaluates the model.

function values_as_in_model(model::Model, include_colon_eq::Bool, varinfo::AbstractVarInfo)
varinfo = setaccs!!(deepcopy(varinfo), (ValuesAsInModelAccumulator(include_colon_eq),))
varinfo = last(evaluate!!(model, varinfo))
return getacc(varinfo, Val(:ValuesAsInModel)).values
end

This is obviously inefficient. We should:

  1. Make ValuesAsInModelAccumulator a default one. It costs almost zero time to do this. Not sure if this will meddle with type stability, but if it does I imagine it should be possible to find a workaround. (cough cough VarNamedTuple...)
  2. Make a new method values_as_in_model(::VarInfo) that just takes the values out from the accumulator.
  3. Check for usage of values_as_in_model(model, vi) in the code base that can be simplified to just values_as_in_model(vi).

I would also prefer renaming one of the two to something else to indicate that one does not evaluate and the other re-evaluates.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions