From a2d61fa3e6d50218164bb46f9c1f0039dcbdaa59 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 16 Feb 2017 16:14:32 +0000 Subject: Skip computing digests when --use_action_cache=false. Does this by delegating responsibility for constructing ActionCache.Entry instances to the ActionCache, and having the StubActionCache return null. Tests show a 1-2% elapsed-time reduction for clean builds: [] Doesn't use interface default methods, because we still need JDK7 for Mac. -- PiperOrigin-RevId: 147722062 MOS_MIGRATED_REVID=147722062 --- .../build/lib/actions/ActionCacheChecker.java | 19 +++++++++++++++---- .../devtools/build/lib/actions/cache/ActionCache.java | 7 +++++++ .../actions/cache/CompactPersistentActionCache.java | 6 ++++++ .../build/lib/actions/cache/StubActionCache.java | 6 ++++++ 4 files changed, 34 insertions(+), 4 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/actions') diff --git a/src/main/java/com/google/devtools/build/lib/actions/ActionCacheChecker.java b/src/main/java/com/google/devtools/build/lib/actions/ActionCacheChecker.java index 4f2a33ce74..717083685f 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/ActionCacheChecker.java +++ b/src/main/java/com/google/devtools/build/lib/actions/ActionCacheChecker.java @@ -267,7 +267,11 @@ public class ActionCacheChecker { } Map usedClientEnv = computeUsedClientEnv(action, clientEnv); ActionCache.Entry entry = - new ActionCache.Entry(action.getKey(), usedClientEnv, action.discoversInputs()); + actionCache.newEntry(action.getKey(), usedClientEnv, action.discoversInputs()); + if (entry == null) { + // Action cache is disabled, don't generate digests. + return; + } for (Artifact output : action.getOutputs()) { // Remove old records from the cache if they used different key. String execPath = output.getExecPathString(); @@ -386,12 +390,19 @@ public class ActionCacheChecker { // Compute the aggregated middleman digest. // Since we never validate action key for middlemen, we should not store // it in the cache entry and just use empty string instead. - entry = new ActionCache.Entry("", ImmutableMap.of(), false); - for (Artifact input : action.getInputs()) { - entry.addFile(input.getExecPath(), metadataHandler.getMetadataMaybe(input)); + entry = actionCache.newEntry("", ImmutableMap.of(), false); + if (entry != null) { + for (Artifact input : action.getInputs()) { + entry.addFile(input.getExecPath(), metadataHandler.getMetadataMaybe(input)); + } } } + // Action cache is disabled, skip the digest. + if (entry == null) { + return; + } + metadataHandler.setDigestForVirtualArtifact(middleman, entry.getFileDigest()); if (changed) { actionCache.put(cacheKey, entry); diff --git a/src/main/java/com/google/devtools/build/lib/actions/cache/ActionCache.java b/src/main/java/com/google/devtools/build/lib/actions/cache/ActionCache.java index 1e123e5f93..0cdec63df4 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/cache/ActionCache.java +++ b/src/main/java/com/google/devtools/build/lib/actions/cache/ActionCache.java @@ -58,6 +58,13 @@ public interface ActionCache { */ void remove(String key); + /** + * Constructs an {@code Entry}. + * @return new {@code Entry} or null if the cache is disabled. + */ + @Nullable + Entry newEntry(String key, Map usedClientEnv, boolean discoversInputs); + /** * An entry in the ActionCache that contains all action input and output * artifact paths and their metadata plus action key itself. diff --git a/src/main/java/com/google/devtools/build/lib/actions/cache/CompactPersistentActionCache.java b/src/main/java/com/google/devtools/build/lib/actions/cache/CompactPersistentActionCache.java index a644000cc3..1be6efa4a0 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/cache/CompactPersistentActionCache.java +++ b/src/main/java/com/google/devtools/build/lib/actions/cache/CompactPersistentActionCache.java @@ -17,6 +17,7 @@ import static java.nio.charset.StandardCharsets.ISO_8859_1; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.devtools.build.lib.actions.cache.ActionCache.Entry; import com.google.devtools.build.lib.concurrent.ThreadSafety.ConditionallyThreadSafe; import com.google.devtools.build.lib.profiler.AutoProfiler; import com.google.devtools.build.lib.util.Clock; @@ -337,6 +338,11 @@ public class CompactPersistentActionCache implements ActionCache { } } + @Override + public Entry newEntry(String key, Map usedClientEnv, boolean discoversInputs) { + return new Entry(key, usedClientEnv, discoversInputs); + } + /** * @return action data encoded as a byte[] array. */ diff --git a/src/main/java/com/google/devtools/build/lib/actions/cache/StubActionCache.java b/src/main/java/com/google/devtools/build/lib/actions/cache/StubActionCache.java index 9e1cdd3663..f1d8c8bdab 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/cache/StubActionCache.java +++ b/src/main/java/com/google/devtools/build/lib/actions/cache/StubActionCache.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.actions.cache; import java.io.PrintStream; +import java.util.Map; /** An {@link ActionCache} which does not store entries. */ public class StubActionCache implements ActionCache { @@ -37,4 +38,9 @@ public class StubActionCache implements ActionCache { @Override public void dump(PrintStream out) {} + + @Override + public Entry newEntry(String key, Map usedClientEnv, boolean discoversInputs) { + return null; + } } -- cgit v1.2.3