Guangya Liu created MESOS-5919:
----------------------------------

             Summary: Improve performance for `Resources.contains` and 
`Resources.filter`
                 Key: MESOS-5919
                 URL: https://issues.apache.org/jira/browse/MESOS-5919
             Project: Mesos
          Issue Type: Bug
            Reporter: Guangya Liu
            Assignee: Guangya Liu


The current logic for `Resources.contains` and `Resources.filter` are as 
following:

{code}
Resources Resources::filter(
    const lambda::function<bool(const Resource&)>& predicate) const
{
  Resources result;
  foreach (const Resource& resource, resources) {
    if (predicate(resource)) {
      result += resource;
    }
  }
  return result;
}
bool Resources::contains(const Resources& that) const
{
  Resources remaining = *this;

  foreach (const Resource& resource, that.resources) {
    // NOTE: We use _contains because Resources only contain valid
    // Resource objects, and we don't want the performance hit of the
    // validity check.
    if (!remaining._contains(resource)) {
      return false;
    }

    remaining -= resource;
  }

  return true;
}
{code}

The problem is that actually all of the {{resource}} object in those two APIs 
are valid and there is no need to validate the resource here, but here both the 
{{remaining -= resource;}} in {{Resources.contains}} and {{result += 
resource;}} in {{Resources::filter}} both include the logic of {{validate}} 
resource, we should remove the {{validate}} logic here by using {{subtract}} 
and {{add}} for those two APIs.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to