Refactor process to continue directly if possible
After this change, the async include scanner processes discovered inclusions in the same thread if it doesn't have to wait for them. This seems to have a small positive impact on build times.
@@ -946,9 +946,31 @@ public class LegacyIncludeScanner implements IncludeScanner {
} else {
actualFuture = previous;
}
+
+ if (actualFuture.isDone()) {
+ Collection<Inclusion> inclusions;
+ try {
+ inclusions = actualFuture.get();
+ } catch (ExecutionException e) {
+ return actualFuture;
+ }
+ return processInclusions(inclusions, source, contextPathPos, contextKind, visited);
+ } else {
return Futures.transformAsync(
actualFuture,
- (inclusions) -> {
+ (inclusions) ->
+ processInclusions(inclusions, source, contextPathPos, contextKind, visited),
+ includePool);
+ }
+ }
+
+ private ListenableFuture<?> processInclusions(
+ Collection<Inclusion> inclusions,
+ Artifact source,
+ int contextPathPos,
+ Kind contextKind,
+ Set<Artifact> visited)
+ throws IOException, InterruptedException {
Preconditions.checkNotNull(inclusions, source);
// Shuffle the inclusions to get better parallelism. See b/62200470.
// Be careful not to modify the original collection! It's shared between any number of
@@ -969,8 +991,6 @@ public class LegacyIncludeScanner implements IncludeScanner {
visited));
}
return Futures.allAsList(allFutures);
- },
- includePool);
}
/** Visits an inclusion starting from a source file. */
