kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ewe...@apache.org
Subject kafka git commit: KAFKA-6168: Connect Schema comparison is slow for large schemas
Date Tue, 21 Nov 2017 22:26:39 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk a133e69b4 -> fd8eb268d


KAFKA-6168: Connect Schema comparison is slow for large schemas

Re-arrange order of comparisons in equals() to evaluate non-composite fields first
Cache hash code

Author: tedyu <yuzhihong@gmail.com>

Reviewers: Randall Hauch <rhauch@gmail.com>, Konstantine Karantasis <konstantine@confluent.io>,
Ewen Cheslack-Postava <ewen@confluent.io>

Closes #4176 from tedyu/trunk


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

Branch: refs/heads/trunk
Commit: fd8eb268d655e00fd1f5e41452a2a30e81daa244
Parents: a133e69
Author: tedyu <yuzhihong@gmail.com>
Authored: Tue Nov 21 14:26:32 2017 -0800
Committer: Ewen Cheslack-Postava <me@ewencp.org>
Committed: Tue Nov 21 14:26:32 2017 -0800

----------------------------------------------------------------------
 .../org/apache/kafka/connect/data/ConnectSchema.java  | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/fd8eb268/connect/api/src/main/java/org/apache/kafka/connect/data/ConnectSchema.java
----------------------------------------------------------------------
diff --git a/connect/api/src/main/java/org/apache/kafka/connect/data/ConnectSchema.java b/connect/api/src/main/java/org/apache/kafka/connect/data/ConnectSchema.java
index 651b2ee..5b0579e 100644
--- a/connect/api/src/main/java/org/apache/kafka/connect/data/ConnectSchema.java
+++ b/connect/api/src/main/java/org/apache/kafka/connect/data/ConnectSchema.java
@@ -93,6 +93,8 @@ public class ConnectSchema implements Schema {
     // Optional human readable documentation describing this schema.
     private final String doc;
     private final Map<String, String> parameters;
+    // precomputed hash code. There is no need to re-compute every time hashCode() is called.
+    private Integer hash = null;
 
     /**
      * Construct a Schema. Most users should not construct schemas manually, preferring {@link
SchemaBuilder} instead.
@@ -283,20 +285,24 @@ public class ConnectSchema implements Schema {
         if (o == null || getClass() != o.getClass()) return false;
         ConnectSchema schema = (ConnectSchema) o;
         return Objects.equals(optional, schema.optional) &&
+                Objects.equals(version, schema.version) &&
+                Objects.equals(name, schema.name) &&
+                Objects.equals(doc, schema.doc) &&
                 Objects.equals(type, schema.type) &&
                 Objects.equals(defaultValue, schema.defaultValue) &&
                 Objects.equals(fields, schema.fields) &&
                 Objects.equals(keySchema, schema.keySchema) &&
                 Objects.equals(valueSchema, schema.valueSchema) &&
-                Objects.equals(name, schema.name) &&
-                Objects.equals(version, schema.version) &&
-                Objects.equals(doc, schema.doc) &&
                 Objects.equals(parameters, schema.parameters);
     }
 
     @Override
     public int hashCode() {
-        return Objects.hash(type, optional, defaultValue, fields, keySchema, valueSchema,
name, version, doc, parameters);
+        if (this.hash == null) {
+            this.hash = Objects.hash(type, optional, defaultValue, fields, keySchema, valueSchema,
name, version, doc,
+                parameters);
+        }
+        return this.hash;
     }
 
     @Override


Mime
View raw message