Uploaded image for project: 'Mesos'
  1. Mesos
  2. MESOS-9325

Optimize `Resources::filter` operation.

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 1.7.1
    • None

    Description

      `Resources::filter()` is a heavily used function. Currently it is O(n^2) due to the `add()` operation for each `Resource`:

      Resources Resources::filter(
          const lambda::function<bool(const Resource&)>& predicate) const
      {
        Resources result;
        foreach (
            const Resource_Unsafe& resource_,
            resourcesNoMutationWithoutExclusiveOwnership) {
          if (predicate(resource_->resource)) {
            result.add(resource_);
          }
        }
        return result;
      }
      

      `add()` is O( n ). This is not necessary. `filter()` operation should only remove `Resource` entries. We should be able to `push_back` the resource to the vector without scanning, making the `filter()` O( n ).

      Attachments

        Activity

          People

            mzhu Meng Zhu
            mzhu Meng Zhu
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: