Details
-
Improvement
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
None
-
None
-
Mesosphere RI-6 Sprint 2018-31
-
1
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 ).