Uploaded image for project: 'OptaPlanner'
  1. OptaPlanner
  2. PLANNER-2647

Inefficient iteration in SolutionDescriptor

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Done
    • Icon: Minor Minor
    • 8.18.0.Final
    • None
    • optaplanner-core
    • None

      SolutionDescriptor (via methods such as getAllFacts()) forces inefficiency to spread throughout OP code. This method first creates a list of all entities and problem facts, only for call sites to then iterate over it, possibly several times. This means that, in order to get anything done, the list will be iterated over at least twice.

      This can be avoided if we instead provide a method visitAllFacts(), which does not return a list, but rather goes over every item that would have been added to the list and applies a visitor on it. In this approach, no list is ever created, and the number of iterations stays at 1, regardless of how many operations need to be performed. (As these can be grouped inside of the visitor.)

            lpetrovi@redhat.com Lukáš Petrovický (Inactive)
            lpetrovi@redhat.com Lukáš Petrovický (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: