Optimistically check the Set within NestedSetVisitor.VisitedState using contains before invoking the heavier add.  This reduces cpu-work and contention.
When blaze is invoked on a large fileset and the build is already up-to-date,
this makes things about 1.9s (33%) faster.
@@ -85,7 +85,10 @@ public final class NestedSetVisitor<E> {
}
private boolean add(Object node) {
- return seenNodes.add(node);
+ // Though it may look redundant, the contains call is much cheaper than the add and can
+ // greatly improve the performance and reduce the contention associated with checking
+ // seenNodes.
+ return !seenNodes.contains(node) && seenNodes.add(node);
}
}
}
