aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/actions
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2017-02-16 16:14:32 +0000
committerGravatar Dmitry Lomov <dslomov@google.com>2017-02-16 16:58:51 +0000
commita2d61fa3e6d50218164bb46f9c1f0039dcbdaa59 (patch)
tree29f2c6b7f0e90ebc6ed79b63a87c0f000c2a3527 /src/main/java/com/google/devtools/build/lib/actions
parent9b75b684655e31ca0f5cb5ed08697e936d4d5c7e (diff)
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
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/actions')
-rw-r--r--src/main/java/com/google/devtools/build/lib/actions/ActionCacheChecker.java19
-rw-r--r--src/main/java/com/google/devtools/build/lib/actions/cache/ActionCache.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/actions/cache/CompactPersistentActionCache.java6
-rw-r--r--src/main/java/com/google/devtools/build/lib/actions/cache/StubActionCache.java6
4 files changed, 34 insertions, 4 deletions
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<String, String> 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.<String, String>of(), false);
- for (Artifact input : action.getInputs()) {
- entry.addFile(input.getExecPath(), metadataHandler.getMetadataMaybe(input));
+ entry = actionCache.newEntry("", ImmutableMap.<String, String>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
@@ -59,6 +59,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<String, String> 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<String, String> 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<String, String> usedClientEnv, boolean discoversInputs) {
+ return null;
+ }
}