mkapalka commented on code in PR #2441: URL: https://github.com/apache/jackrabbit-oak/pull/2441#discussion_r2266519875
########## oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/async/facets/ElasticStatisticalFacetAsyncProvider.java: ########## @@ -171,31 +179,28 @@ private void processAggregations(Map<String, Aggregate> aggregations) { private void computeStatisticalFacets() { for (String facetKey : allFacets.keySet()) { if (accessibleFacetCounts.containsKey(facetKey)) { - Map<String, Integer> accessibleFacet = accessibleFacetCounts.get(facetKey); + Map<String, MutableInt> accessibleFacet = accessibleFacetCounts.get(facetKey); List<FulltextIndex.Facet> uncheckedFacet = allFacets.get(facetKey); for (FulltextIndex.Facet facet : uncheckedFacet) { if (accessibleFacet.containsKey(facet.getLabel())) { - double sampleProportion = (double) accessibleFacet.get(facet.getLabel()) / sampled; + double sampleProportion = (double) accessibleFacet.get(facet.getLabel()).intValue() / sampled; Review Comment: Minor detail: you can use `MutableInt.doubleValue()` to make this more explicit (and avoid casting) ########## oak-search-elastic/src/main/java/org/apache/jackrabbit/oak/plugins/index/elastic/query/async/facets/ElasticStatisticalFacetAsyncProvider.java: ########## @@ -171,31 +179,28 @@ private void processAggregations(Map<String, Aggregate> aggregations) { private void computeStatisticalFacets() { for (String facetKey : allFacets.keySet()) { if (accessibleFacetCounts.containsKey(facetKey)) { - Map<String, Integer> accessibleFacet = accessibleFacetCounts.get(facetKey); + Map<String, MutableInt> accessibleFacet = accessibleFacetCounts.get(facetKey); List<FulltextIndex.Facet> uncheckedFacet = allFacets.get(facetKey); for (FulltextIndex.Facet facet : uncheckedFacet) { if (accessibleFacet.containsKey(facet.getLabel())) { - double sampleProportion = (double) accessibleFacet.get(facet.getLabel()) / sampled; + double sampleProportion = (double) accessibleFacet.get(facet.getLabel()).intValue() / sampled; // returned count is the minimum between the accessible count and the count computed from the sample - accessibleFacet.put(facet.getLabel(), Math.min(facet.getCount(), (int) (sampleProportion * totalHits))); + accessibleFacet.put(facet.getLabel(), new MutableInt(Math.min(facet.getCount(), (int) (sampleProportion * totalHits)))); Review Comment: Detail: since this PR is about micro-optimization, we could go one step further and avoid 3 x hashmap lookup + constructing new `MutableInt` by using `accessibleFacet.compute(...)` or doing it more explicitly, e.g.: ``` var curr = accessibleFacet.get(facet.getLabel()); if (curr != null) { var sampleProportion = ... curr.setValue(Math.min(...)) } ``` -- 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: oak-dev-unsubscr...@jackrabbit.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org