garydgregory commented on PR #1524:
URL: https://github.com/apache/commons-lang/pull/1524#issuecomment-6921973990

   Thank you for the proposal and the benchmarking work, @IcoreE.
   
   I’m closing this PR because the collision examples reported in 
[LANG-1802](https://issues.apache.org/jira/browse/LANG-1802) are already 
addressed by the current implementation and covered by existing regression 
tests:
   
   ```java
   return Objects.hash(end, negated, start);
   ```
   
   This implementation satisfies Java’s `equals()`/`hashCode()` contract. 
Collisions between unequal objects are permitted; the practical question is 
whether a change improves collection performance.
   
   Unfortunately, the proposed bit packing introduces poor bucket distribution 
for single-character ranges. For `CharRange.is(c)`, the hash is `(c << 16) | 
c`. After the JDK’s hash spreading, this becomes `c << 16`, placing all such 
ranges in bucket zero for table capacities up to 65,536. This affects 
`CharSet`, which stores ranges in a `LinkedHashSet`. A focused reproduction 
with 26 lowercase letters used 26 buckets with the current implementation, but 
only one tree bucket with this change.
   
   The benchmark demonstrates faster calculation of the proposed formula, but 
it does not measure the resulting collection behavior. It also benchmarks 
separate implementations of the formulas rather than calling 
`CharRange.hashCode()`, and adds no JUnit regression assertions.
   
   Given that the reported examples are already handled and this replacement 
introduces a bucket-distribution regression, I think retaining the current 
implementation is the appropriate choice. A future optimization supported by 
representative collection benchmarks and regression tests would be welcome.
   
   Thank you again for investigating this.


-- 
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]

Reply via email to