You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by tg...@apache.org on 2016/11/16 21:23:02 UTC

[4/4] incubator-beam git commit: Reduce incidence of Namespace StringKey comparisons

Reduce incidence of Namespace StringKey comparisons

If the Namespace of a TimerData reports itself as being equal to the
other namespace, immediately return 0 rather than generating the string
keys and comparing them.


Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/3e6a4f4a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/3e6a4f4a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/3e6a4f4a

Branch: refs/heads/master
Commit: 3e6a4f4a49344871430d2711e934b0493c17499f
Parents: c695ef4
Author: Thomas Groh <tg...@google.com>
Authored: Tue Nov 8 14:18:58 2016 -0800
Committer: Thomas Groh <tg...@google.com>
Committed: Wed Nov 16 13:22:41 2016 -0800

----------------------------------------------------------------------
 .../java/org/apache/beam/sdk/util/TimerInternals.java  | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/3e6a4f4a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/TimerInternals.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/TimerInternals.java b/sdks/java/core/src/main/java/org/apache/beam/sdk/util/TimerInternals.java
index 743f3f7..5d4a72d 100644
--- a/sdks/java/core/src/main/java/org/apache/beam/sdk/util/TimerInternals.java
+++ b/sdks/java/core/src/main/java/org/apache/beam/sdk/util/TimerInternals.java
@@ -230,12 +230,17 @@ public interface TimerInternals {
      * arbitrary.
      */
     @Override
-    public int compareTo(TimerData o) {
+    public int compareTo(TimerData that) {
+      if (this.equals(that)) {
+        return 0;
+      }
       ComparisonChain chain =
-          ComparisonChain.start().compare(timestamp, o.getTimestamp()).compare(domain, o.domain);
-      if (chain.result() == 0) {
+          ComparisonChain.start()
+              .compare(this.timestamp, that.getTimestamp())
+              .compare(this.domain, that.domain);
+      if (chain.result() == 0 && !this.namespace.equals(that.namespace)) {
         // Obtaining the stringKey may be expensive; only do so if required
-        chain = chain.compare(namespace.stringKey(), o.namespace.stringKey());
+        chain = chain.compare(namespace.stringKey(), that.namespace.stringKey());
       }
       return chain.result();
     }