You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2022/02/04 00:36:10 UTC

[GitHub] [pinot] richardstartin opened a new pull request #8124: do not use Arrays.hashCode in ExpressionContext or FunctionContext

richardstartin opened a new pull request #8124:
URL: https://github.com/apache/pinot/pull/8124


   I noticed very high allocation rate from using `ExpressionContext` as a `HashMap` key when profiling a benchmark:
   <img width="1307" alt="Screenshot 2022-02-04 at 00 19 36" src="https://user-images.githubusercontent.com/16439049/152452326-2e13ce08-b3aa-4b60-9575-e7fc0b998861.png">
   
   This is because `Arrays.hashCode` boxes its arguments.
   
   Computing the hash code manually reduces allocation in benchmark runs significantly:
   
   before
   ```
   Benchmark                                                                               (_intBaseValue)  (_numRows)  Mode  Cnt        Score          Error   Units
   BenchmarkFilteredAggregations.testFilteredAggregations:·gc.alloc.rate.norm                            0     1500000  avgt    5   477029.513 ±     4265.923    B/op
   BenchmarkFilteredAggregations.testNonFilteredAggregations:·gc.alloc.rate.norm                         0     1500000  avgt    5  1453348.554 ±    38671.676    B/op
   ```
   
   after
   ```
   Benchmark                                                                               (_intBaseValue)  (_numRows)  Mode  Cnt        Score          Error   Units
   BenchmarkFilteredAggregations.testFilteredAggregations:·gc.alloc.rate.norm                            0     1500000  avgt    5   372573.234 ±   299663.490    B/op
   BenchmarkFilteredAggregations.testNonFilteredAggregations:·gc.alloc.rate.norm                         0     1500000  avgt    5  1085451.680 ±  1751019.851    B/op
   ```
   


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] siddharthteotia merged pull request #8124: do not use Objects.hash in ExpressionContext or FunctionContext

Posted by GitBox <gi...@apache.org>.
siddharthteotia merged pull request #8124:
URL: https://github.com/apache/pinot/pull/8124


   


-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] siddharthteotia commented on a change in pull request #8124: do not use Objects.hash in ExpressionContext or FunctionContext

Posted by GitBox <gi...@apache.org>.
siddharthteotia commented on a change in pull request #8124:
URL: https://github.com/apache/pinot/pull/8124#discussion_r799719274



##########
File path: pinot-common/src/main/java/org/apache/pinot/common/request/context/FunctionContext.java
##########
@@ -84,7 +84,7 @@ public boolean equals(Object o) {
 
   @Override
   public int hashCode() {
-    return Objects.hash(_type, _functionName, _arguments);
+    return 31 * 31 * _type.hashCode() + 31 * _functionName.hashCode() + _arguments.hashCode();

Review comment:
       Do we need to see if arguments.hashCode() internally uses Objects.hash() and if that needs to be fixed too ?




-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org


[GitHub] [pinot] richardstartin commented on a change in pull request #8124: do not use Objects.hash in ExpressionContext or FunctionContext

Posted by GitBox <gi...@apache.org>.
richardstartin commented on a change in pull request #8124:
URL: https://github.com/apache/pinot/pull/8124#discussion_r799735990



##########
File path: pinot-common/src/main/java/org/apache/pinot/common/request/context/FunctionContext.java
##########
@@ -84,7 +84,7 @@ public boolean equals(Object o) {
 
   @Override
   public int hashCode() {
-    return Objects.hash(_type, _functionName, _arguments);
+    return 31 * 31 * _type.hashCode() + 31 * _functionName.hashCode() + _arguments.hashCode();

Review comment:
       Fortunately we don’t- the frames for ArrayList are in the flame graph above. After this change, that whole stack trace disappears from allocation profiles. 




-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org