From 59997091c8f991b55899d6feb5d5c05e720f78a7 Mon Sep 17 00:00:00 2001 From: Tommaso Teofili Date: Tue, 1 Aug 2017 15:00:25 +0200 Subject: [PATCH] LUCENE-7915 - avoid looping over merges on best merge selection --- .../org/apache/lucene/index/TieredMergePolicy.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/index/TieredMergePolicy.java b/lucene/core/src/java/org/apache/lucene/index/TieredMergePolicy.java index c020a6de062..bba57efff39 100644 --- a/lucene/core/src/java/org/apache/lucene/index/TieredMergePolicy.java +++ b/lucene/core/src/java/org/apache/lucene/index/TieredMergePolicy.java @@ -298,7 +298,7 @@ public class TieredMergePolicy extends MergePolicy { // call size() once per segment and sort by that: Map sizeInBytes = getSegmentSizes(writer, infos.asList()); - Collections.sort(infosSorted, new SegmentByteSizeDescending(sizeInBytes)); + infosSorted.sort(new SegmentByteSizeDescending(sizeInBytes)); // Compute total index bytes & print details about the index long totIndexBytes = 0; @@ -439,9 +439,7 @@ public class TieredMergePolicy extends MergePolicy { } final OneMerge merge = new OneMerge(best); spec.add(merge); - for(SegmentCommitInfo info : merge.segments) { - toBeMerged.add(info); - } + toBeMerged.addAll(merge.segments); if (verbose(writer)) { message(" add merge=" + writer.segString(merge.segments) + " size=" + String.format(Locale.ROOT, "%.3f MB", bestMergeBytes/1024./1024.) + " score=" + String.format(Locale.ROOT, "%.3f", bestScore.getScore()) + " " + bestScore.getExplanation() + (bestTooLarge ? " [max merge]" : ""), writer); @@ -553,7 +551,7 @@ public class TieredMergePolicy extends MergePolicy { return null; } - Collections.sort(eligible, new SegmentByteSizeDescending(sizeInBytes)); + eligible.sort(new SegmentByteSizeDescending(sizeInBytes)); if (verbose(writer)) { message("eligible=" + eligible, writer); @@ -614,7 +612,7 @@ public class TieredMergePolicy extends MergePolicy { // call size() once per segment and sort by that: Map sizeInBytes = getSegmentSizes(writer, infos.asList()); - Collections.sort(eligible, new SegmentByteSizeDescending(sizeInBytes)); + eligible.sort(new SegmentByteSizeDescending(sizeInBytes)); if (verbose(writer)) { message("eligible=" + eligible, writer);