Precompute non-configurable attributes at RuleClass level
Previously we created this collection for each AggregatingAttributeMapper,
which we create at least every attribute encountered. Calculate the collection
up front to avoid wasting time and memory.
--
MOS_MIGRATED_REVID=109805907
diff --git a/src/main/java/com/google/devtools/build/lib/packages/AggregatingAttributeMapper.java b/src/main/java/com/google/devtools/build/lib/packages/AggregatingAttributeMapper.java
index ff1d4b2..9516e27 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/AggregatingAttributeMapper.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/AggregatingAttributeMapper.java
@@ -46,19 +46,13 @@
* unconditionally available to computed defaults no matter what dependencies
* they've declared.
*/
- private final List<String> nonconfigurableAttributes;
+ private final List<String> nonConfigurableAttributes;
private AggregatingAttributeMapper(Rule rule) {
super(rule.getPackage(), rule.getRuleClassObject(), rule.getLabel(),
rule.getAttributeContainer());
- ImmutableList.Builder<String> nonconfigurableAttributesBuilder = ImmutableList.builder();
- for (Attribute attr : rule.getAttributes()) {
- if (!attr.isConfigurable()) {
- nonconfigurableAttributesBuilder.add(attr.getName());
- }
- }
- nonconfigurableAttributes = nonconfigurableAttributesBuilder.build();
+ nonConfigurableAttributes = rule.getRuleClassObject().getNonConfigurableAttributes();
}
public static AggregatingAttributeMapper of(Rule rule) {
@@ -374,7 +368,7 @@
@Override
public <T> T get(String attributeName, Type<T> type) {
owner.checkType(attributeName, type);
- if (nonconfigurableAttributes.contains(attributeName)) {
+ if (nonConfigurableAttributes.contains(attributeName)) {
return owner.get(attributeName, type);
}
if (!directMap.containsKey(attributeName)) {
@@ -393,7 +387,7 @@
@Override public Label getLabel() { return owner.getLabel(); }
@Override public Iterable<String> getAttributeNames() {
return ImmutableList.<String>builder()
- .addAll(directMap.keySet()).addAll(nonconfigurableAttributes).build();
+ .addAll(directMap.keySet()).addAll(nonConfigurableAttributes).build();
}
@Override
public void visitLabels(AcceptsLabelAttribute observer) { owner.visitLabels(observer); }
diff --git a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
index 252bbfd..2a3137a 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/RuleClass.java
@@ -914,6 +914,9 @@
*/
private final ImmutableList<Attribute> attributes;
+ /** Names of the non-configurable attributes of this rule class. */
+ private final ImmutableList<String> nonConfigurableAttributes;
+
/**
* The set of implicit outputs generated by a rule, expressed as a function
* of that rule.
@@ -1083,12 +1086,17 @@
this.configurationFragmentPolicy = configurationFragmentPolicy;
this.supportsConstraintChecking = supportsConstraintChecking;
- // create the index:
+ // Create the index and collect non-configurable attributes.
int index = 0;
attributeIndex = new HashMap<>(attributes.length);
+ ImmutableList.Builder<String> nonConfigurableAttributesBuilder = ImmutableList.builder();
for (Attribute attribute : attributes) {
attributeIndex.put(attribute.getName(), index++);
+ if (!attribute.isConfigurable()) {
+ nonConfigurableAttributesBuilder.add(attribute.getName());
+ }
}
+ this.nonConfigurableAttributes = nonConfigurableAttributesBuilder.build();
}
private void validateNoClashInPublicNames(Attribute[] attributes) {
@@ -1214,6 +1222,11 @@
return attributes;
}
+ /** Returns set of non-configurable attribute names defined for this class of rule. */
+ public List<String> getNonConfigurableAttributes() {
+ return nonConfigurableAttributes;
+ }
+
public PredicateWithMessage<Rule> getValidityPredicate() {
return validityPredicate;
}