mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject [4/4] mesos git commit: Resource Math: Substituted DeleteSubrange with Swap + RemoveLast.
Date Tue, 26 Jan 2016 20:19:12 GMT
Resource Math: Substituted DeleteSubrange with Swap + RemoveLast.

This improves 'operator-=' performance for Resources.

Review: https://reviews.apache.org/r/42761


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/8821a756
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/8821a756
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/8821a756

Branch: refs/heads/master
Commit: 8821a7562b503e943c941e1e3e0d808b06ae8849
Parents: 9e0528e
Author: Joris Van Remoortere <joris.van.remoortere@gmail.com>
Authored: Mon Jan 25 15:18:58 2016 -0800
Committer: Joris Van Remoortere <joris.van.remoortere@gmail.com>
Committed: Tue Jan 26 12:00:27 2016 -0800

----------------------------------------------------------------------
 src/common/resources.cpp | 7 ++++++-
 src/v1/resources.cpp     | 7 ++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/8821a756/src/common/resources.cpp
----------------------------------------------------------------------
diff --git a/src/common/resources.cpp b/src/common/resources.cpp
index 0fcf860..588a279 100644
--- a/src/common/resources.cpp
+++ b/src/common/resources.cpp
@@ -1407,7 +1407,12 @@ Resources& Resources::operator-=(const Resource& that)
         // to do the validation because we want to strip negative
         // scalar Resource object.
         if (validate(*resource).isSome() || isEmpty(*resource)) {
-          resources.DeleteSubrange(i, 1);
+          // As `resources` is not ordered, and erasing an element
+          // from the middle using `DeleteSubrange` is expensive, we
+          // swap with the last element and then shrink the
+          // 'RepeatedPtrField' by one.
+          resources.Mutable(i)->Swap(resources.Mutable(resources.size() - 1));
+          resources.RemoveLast();
         }
 
         break;

http://git-wip-us.apache.org/repos/asf/mesos/blob/8821a756/src/v1/resources.cpp
----------------------------------------------------------------------
diff --git a/src/v1/resources.cpp b/src/v1/resources.cpp
index 126e5a2..fc7c885 100644
--- a/src/v1/resources.cpp
+++ b/src/v1/resources.cpp
@@ -1402,7 +1402,12 @@ Resources& Resources::operator-=(const Resource& that)
         // to do the validation because we want to strip negative
         // scalar Resource object.
         if (validate(*resource).isSome() || isEmpty(*resource)) {
-          resources.DeleteSubrange(i, 1);
+          // As `resources` is not ordered, and erasing an element
+          // from the middle using `DeleteSubrange` is expensive, we
+          // swap with the last element and then shrink the
+          // 'RepeatedPtrField' by one.
+          resources.Mutable(i)->Swap(resources.Mutable(resources.size() - 1));
+          resources.RemoveLast();
         }
 
         break;


Mime
View raw message