Skip to content

Commit 63846f1

Browse files
authored
Improve DeltaList behavior for large projects (#335)
* Improve DeltaList behavior with large codebase I have been experimenting with a large code base to try to improve Quarkus build time and I stumbled upon the fact that DeltaList was very inefficient in these cases. In this commit, I keep the ordering even if not actually important. I will push further optimizations in a second commit that we can discuss further. Fixes #334 * Use for loops instead of streams
1 parent ab3f845 commit 63846f1

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,19 +1840,21 @@ private boolean hasInputFileTreeChanged(IncrementalBuildHelper ibh, Set<File> in
18401840
}
18411841
Path mojoConfigFile = mojoConfigBase.resolve(INPUT_FILES_LST_FILENAME);
18421842

1843-
List<String> oldInputFiles = Collections.emptyList();
1843+
Set<String> oldInputFiles = Collections.emptySet();
18441844
if (Files.isRegularFile(mojoConfigFile)) {
18451845
try {
1846-
oldInputFiles = Files.readAllLines(mojoConfigFile);
1846+
oldInputFiles = new HashSet<>(Files.readAllLines(mojoConfigFile));
18471847
} catch (IOException e) {
18481848
// we cannot read the mojo config file, so don't do anything beside logging
18491849
getLog().warn("Error while reading old mojo status: " + mojoConfigFile);
18501850
return false;
18511851
}
18521852
}
18531853

1854-
List<String> newInputFiles =
1855-
inputFiles.stream().sorted().map(File::getAbsolutePath).collect(Collectors.toList());
1854+
Set<String> newInputFiles = inputFiles.stream()
1855+
.sorted()
1856+
.map(File::getAbsolutePath)
1857+
.collect(Collectors.toCollection(LinkedHashSet::new));
18561858

18571859
try {
18581860
Files.write(mojoConfigFile, newInputFiles);

src/main/java/org/apache/maven/plugin/compiler/DeltaList.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,31 @@
1818
*/
1919
package org.apache.maven.plugin.compiler;
2020

21-
import java.util.ArrayList;
2221
import java.util.Collection;
2322
import java.util.Collections;
24-
import java.util.List;
23+
import java.util.Set;
24+
import java.util.TreeSet;
2525

2626
/**
2727
* Show the modifications between two lists.
2828
*/
29-
final class DeltaList<E> {
29+
final class DeltaList<E extends Comparable<E>> {
3030

31-
private final List<E> added;
32-
private final List<E> removed;
31+
private final Set<E> added = new TreeSet<>();
32+
private final Set<E> removed = new TreeSet<>();
3333
private final boolean hasChanged;
3434

3535
DeltaList(Collection<E> oldList, Collection<E> newList) {
36-
this.added = new ArrayList<>(newList);
37-
this.removed = new ArrayList<>(oldList);
38-
added.removeAll(oldList);
39-
removed.removeAll(newList);
36+
for (E newListItem : newList) {
37+
if (!oldList.contains(newListItem)) {
38+
added.add(newListItem);
39+
}
40+
}
41+
for (E oldListItem : oldList) {
42+
if (!newList.contains(oldListItem)) {
43+
removed.add(oldListItem);
44+
}
45+
}
4046
this.hasChanged = !added.isEmpty() || !removed.isEmpty();
4147
}
4248

0 commit comments

Comments
 (0)