diff options
author | Googler <noreply@google.com> | 2018-03-22 14:27:00 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-03-22 14:28:29 -0700 |
commit | 8402a23a5432e363d3c09bae0b020abb35e7f468 (patch) | |
tree | 63fd917221db063fbc6e1c6bb86770342427fde4 /src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetVisitor.java | |
parent | 251e8e5cbd4411f2c061ca34147ee7631c539d92 (diff) |
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.
PiperOrigin-RevId: 190125803
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetVisitor.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetVisitor.java | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetVisitor.java b/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetVisitor.java index c66ef27662..090b8e33bb 100644 --- a/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetVisitor.java +++ b/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetVisitor.java @@ -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); } } } |