BackendArchitectX commented on code in PR #19915:
URL: https://github.com/apache/pinot/pull/19915#discussion_r4345289536


##########
pinot-broker/src/main/java/org/apache/pinot/broker/routing/instanceselector/ReplicaGroupInstanceSelector.java:
##########
@@ -73,6 +75,45 @@ public class ReplicaGroupInstanceSelector extends 
BaseInstanceSelector {
 
   private static final Logger LOGGER = 
LoggerFactory.getLogger(ReplicaGroupInstanceSelector.class);
 
+  // Immutable key for instance groups that reduces hash collisions.
+  static final class InstanceSetKey implements Comparable<InstanceSetKey> {
+    private final String[] _instances;
+    private final int _hashCode;
+
+    InstanceSetKey(Set<String> instances) {
+      _instances = instances.toArray(new String[0]);
+      Arrays.sort(_instances);
+
+      int hash = 1;
+      for (String instance : _instances) {
+        hash = 31 * hash + HashCommon.mix(instance.hashCode());
+      }
+      _hashCode = hash;
+    }
+
+    @Override
+    public int hashCode() {
+      return _hashCode;
+    }
+
+    @Override
+    public boolean equals(Object object) {
+      if (this == object) {
+        return true;
+      }
+      if (!(object instanceof InstanceSetKey)) {
+        return false;
+      }
+      InstanceSetKey other = (InstanceSetKey) object;
+      return _hashCode == other._hashCode && Arrays.equals(_instances, 
other._instances);
+    }
+
+    @Override
+    public int compareTo(InstanceSetKey other) {

Review Comment:
   Thanks for the review! I kept `Comparable` intentionally because `HashMap` 
uses it to navigate treeified collision buckets when keys have identical 
hashes. Since this change specifically addresses hash-collision performance, I 
think it's worth retaining as a safeguard against residual collisions.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to