aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test
diff options
context:
space:
mode:
authorGravatar Greg Estren <gregce@google.com>2016-09-28 14:49:12 +0000
committerGravatar Yun Peng <pcloudy@google.com>2016-09-28 16:06:29 +0000
commitad1a77e296fe5f05624109f3af04c5bc3257e9b6 (patch)
treef991b43ac5fccf611f71c9a49af9eef5d7797fe8 /src/test
parenteb87208599cdb9ede31efe793485e9096ab4a773 (diff)
Eliminates performance overhead of --experimental_dynamic_configs=notrim.
Before this change, a non-trivial real-world build was measured to have about 20% analysis time overhead. After, that's theoretically down to 2.4%. But that's only the analysis phase, so the impact on full builds is smaller. And the impact on analysis-cached builds is zero. And practical tests show no obvious difference (JProfiler is probably overstating the impact since it excludes known heavyweight methods). The improvements, in short: - Optimize a sanity check that expects each <Attribute, Label> pair to only have one transition. This alone was over half the original performance penalty. - Simplify logic for null configuration deps (of which there are many, e.g.: all source files) - Skip a check for required fragments not available in the configuration. This is irrelevant for notrim mode. There are still some places we could optimize. Dependency.withNullConfiguration in particular takes measurable time (I think from being constructed all the time and in its hashCode calls). But this doesn't seem pressing given the new numbers. -- MOS_MIGRATED_REVID=134533452
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/ConfigurationsForTargetsTest.java74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ConfigurationsForTargetsTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ConfigurationsForTargetsTest.java
new file mode 100644
index 0000000000..b68a1190ef
--- /dev/null
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/ConfigurationsForTargetsTest.java
@@ -0,0 +1,74 @@
+// Copyright 2016 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.build.lib.skyframe;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.fail;
+
+import com.google.common.base.VerifyException;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.ListMultimap;
+import com.google.common.collect.Multimap;
+import com.google.common.collect.SetMultimap;
+import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
+import com.google.devtools.build.lib.testutil.FoundationTestCase;
+import com.google.devtools.build.lib.testutil.Suite;
+import com.google.devtools.build.lib.testutil.TestSpec;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/**
+ * Tests {@link ConfiguredTargetFunction}'s logic for determining each target's
+ * {@link BuildConfiguration}.
+ */
+@TestSpec(size = Suite.SMALL_TESTS)
+@RunWith(JUnit4.class)
+public class ConfigurationsForTargetsTest extends FoundationTestCase {
+
+ // TODO(gregce): add thorough unit testing for getDynamicConfigurations.
+
+ @Test
+ public void testPutOnlyEntryWithSetMultimap() throws Exception {
+ internalTestPutOnlyEntry(HashMultimap.create());
+ }
+
+ /**
+ * Unlike {@link SetMultimap}, {@link ListMultimap} allows duplicate <Key, value> pairs. Make
+ * sure that doesn't fool {@link ConfiguredTargetFunction#putOnlyEntry}.
+ */
+ @Test
+ public void testPutOnlyEntryWithListMultimap() throws Exception {
+ internalTestPutOnlyEntry(ArrayListMultimap.create());
+ }
+
+ private void internalTestPutOnlyEntry(Multimap<String, String> map) throws Exception {
+ ConfiguredTargetFunction.putOnlyEntry(map, "foo", "bar");
+ ConfiguredTargetFunction.putOnlyEntry(map, "baz", "bar");
+ try {
+ ConfiguredTargetFunction.putOnlyEntry(map, "foo", "baz");
+ fail("Expected an exception when trying to add a new value to an existing key");
+ } catch (VerifyException e) {
+ assertThat(e).hasMessage("couldn't insert baz: map already has key foo");
+ }
+ try {
+ ConfiguredTargetFunction.putOnlyEntry(map, "foo", "bar");
+ fail("Expected an exception when trying to add a pre-existing <key, value> pair");
+ } catch (VerifyException e) {
+ assertThat(e).hasMessage("couldn't insert bar: map already has key foo");
+ }
+ }
+}