aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/skyframe
diff options
context:
space:
mode:
authorGravatar Greg Estren <gregce@google.com>2016-09-29 17:29:02 +0000
committerGravatar Yun Peng <pcloudy@google.com>2016-09-30 08:12:24 +0000
commitf4612304c23070aa32a87a9eebb682c30e0f0ab2 (patch)
tree217cab7c0dd0aa675c4c6cdaf14d9b52e6da0b67 /src/main/java/com/google/devtools/build/lib/skyframe
parent14251a4ca0d61be24cd96506b9538b1f54047417 (diff)
ConfiguredTargetFunction#getDynamicConfigurations: halve the number of AttributeAndLabel instantiations. This shaves 25% off the method's execution time in --experimental_dynamic_configs=notrim mode.
This isn't a crucial optimization, since getDynamicConfigurations is already fast. Profiling: $ bazel shutdown; bazel build --nobuild //testapp:cc --experimental_dynamic_configs=notrim shows getDynamicConfigurations takes 1.3% of the analysis phase's CPU time before this change and 1.0% after. Before this change, AttributeAndLabel instantiation took 44% of the method's CPU time. After: 30%. Profiling done with JProfiler. -- MOS_MIGRATED_REVID=134677107
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java
index 862a5a95ef..034c9647a0 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java
@@ -77,8 +77,11 @@ import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
import com.google.devtools.build.skyframe.ValueOrException;
import com.google.devtools.build.skyframe.ValueOrException2;
+
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -466,11 +469,17 @@ final class ConfiguredTargetFunction implements SkyFunction {
// This map is used heavily by all builds. Inserts and gets should be as fast as possible.
Multimap<AttributeAndLabel, Dependency> trimmedDeps = LinkedHashMultimap.create();
+ // Performance optimization: This method iterates over originalDeps twice. By storing
+ // AttributeAndLabel instances in this list, we avoid having to recreate them the second time
+ // (particularly avoid recomputing their hash codes). Profiling shows this shaves 25% off this
+ // method's execution time (at the time of this comment).
+ ArrayList<AttributeAndLabel> attributesAndLabels = new ArrayList<>(originalDeps.size());
+
for (Map.Entry<Attribute, Dependency> depsEntry : originalDeps.entries()) {
Dependency dep = depsEntry.getValue();
AttributeAndLabel attributeAndLabel =
new AttributeAndLabel(depsEntry.getKey(), dep.getLabel());
-
+ attributesAndLabels.add(attributeAndLabel);
// Certain targets (like output files) trivially re-use their input configuration. Likewise,
// deps with null configurations (e.g. source files), can be trivially computed. So we skip
// all logic in this method for these cases and just reinsert their original configurations
@@ -590,10 +599,10 @@ final class ConfiguredTargetFunction implements SkyFunction {
// Re-assemble the output map with the same value ordering (e.g. each attribute's dep labels
// appear in the same order) as the input.
+ Iterator<AttributeAndLabel> iterator = attributesAndLabels.iterator();
OrderedSetMultimap<Attribute, Dependency> result = OrderedSetMultimap.create();
for (Map.Entry<Attribute, Dependency> depsEntry : originalDeps.entries()) {
- AttributeAndLabel attrAndLabel =
- new AttributeAndLabel(depsEntry.getKey(), depsEntry.getValue().getLabel());
+ AttributeAndLabel attrAndLabel = iterator.next();
if (depsEntry.getValue().hasStaticConfiguration()) {
result.put(attrAndLabel.attribute, depsEntry.getValue());
} else {