From 42ff95a1202cd18cc3348ed6a442de5eb95845bd Mon Sep 17 00:00:00 2001 From: Chi Wang Date: Thu, 18 Aug 2022 04:55:16 -0700 Subject: [PATCH] Avoid unnecessary iteration on action inputs. Closes #16118. PiperOrigin-RevId: 468429355 Change-Id: I3b32a28ce3e7c6711fdc15839e5a88fad812184c --- .../build/lib/remote/RemoteExecutionCache.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteExecutionCache.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteExecutionCache.java index d38c39206b3776..2414c9f676875b 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteExecutionCache.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteExecutionCache.java @@ -28,6 +28,7 @@ import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; import com.google.common.util.concurrent.ListenableFuture; import com.google.devtools.build.lib.profiler.Profiler; import com.google.devtools.build.lib.profiler.SilentCloseable; @@ -82,13 +83,13 @@ public void ensureInputsPresent( Map additionalInputs, boolean force) throws IOException, InterruptedException { - ImmutableSet allDigests = - ImmutableSet.builder() - .addAll(merkleTree.getAllDigests()) - .addAll(additionalInputs.keySet()) - .build(); + Iterable merkleTreeAllDigests; + try (SilentCloseable s = Profiler.instance().profile("merkleTree.getAllDigests()")) { + merkleTreeAllDigests = merkleTree.getAllDigests(); + } + Iterable allDigests = Iterables.concat(merkleTreeAllDigests, additionalInputs.keySet()); - if (allDigests.isEmpty()) { + if (Iterables.isEmpty(allDigests)) { return; }