[ 
https://issues.apache.org/jira/browse/LUCENE-10660?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17571369#comment-17571369
 ] 

Adrien Grand commented on LUCENE-10660:
---------------------------------------

The change made sense to me and I merged it, thank you [~tangdh]!

> precompute the max level in LogMergePolicy
> ------------------------------------------
>
>                 Key: LUCENE-10660
>                 URL: https://issues.apache.org/jira/browse/LUCENE-10660
>             Project: Lucene - Core
>          Issue Type: Improvement
>          Components: core/index
>    Affects Versions: 9.2
>            Reporter: tang donghai
>            Priority: Minor
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> I notice LogMergePolicy#findMerges will always calculate  max level on the 
> right side when find the next segments to merge.
>  
> I think we could calculate the max levels only once, and when we need the max 
> level, we could simply
> {code:java}
> float maxLevel = maxLevels[start];
> {code}
> and the precomputed code looks like below, compare each level in levels from 
> right to left 
> {code:java}
> float[] maxLevels = new float[numMergeableSegments + 1];
> maxLevels[numMergeableSegments] = -1.0f;
> for (int i = numMergeableSegments - 1; i >= 0; i--) {
>       maxLevels[i] = Math.max(levels.get(i).level, maxLevels[i + 1]);
> }
> {code}
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to