diff options
author | Greg Estren <gregce@google.com> | 2016-09-29 18:44:03 +0000 |
---|---|---|
committer | Yun Peng <pcloudy@google.com> | 2016-09-30 08:13:21 +0000 |
commit | 13a73e420acf83d888e86dea4d726f5c59587858 (patch) | |
tree | 89a1f02d1018e031489bf8d0a35b6c6381438230 | |
parent | ead58ae8e17257eabf91f512b64da4f85dbe06a1 (diff) |
Lazily evaluate hash codes for ConfiguredTargetFunction#AttributeAndLabel.
Profiling shows this shaves off 8% of getDynamicConfigurations' CPU time.
And brings down AttributeAndLabel instantiation from 30% of that time to 24%.
Over a simple cc_binary, this reduces the number of Objects.hash calls
by 96%.
--
MOS_MIGRATED_REVID=134687748
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetFunction.java | 8 |
1 files changed, 6 insertions, 2 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 034c9647a0..9c5c164384 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 @@ -377,12 +377,11 @@ final class ConfiguredTargetFunction implements SkyFunction { private static final class AttributeAndLabel { final Attribute attribute; final Label label; - final int hashCode; + Integer hashCode; AttributeAndLabel(Attribute attribute, Label label) { this.attribute = attribute; this.label = label; - this.hashCode = Objects.hash(this.attribute, this.label); } @Override @@ -396,6 +395,11 @@ final class ConfiguredTargetFunction implements SkyFunction { @Override public int hashCode() { + if (hashCode == null) { + // Not every <Attribute, Label> pair gets hashed. So only evaluate for the instances that + // need it. This can significantly reduce the number of evaluations. + hashCode = Objects.hash(this.attribute, this.label); + } return hashCode; } } |