From b80c21a3eee246a1e9c7b9b2b1e19f769f93430a Mon Sep 17 00:00:00 2001 From: janakr Date: Mon, 23 Oct 2017 18:16:39 +0200 Subject: Memoize configuration supplier in InfoCommand. Previous implementation never actually assigned to the configuration, so we were redoing Skyframe graph setup each time. We still cached actual loading/analysis work, but unnecessarily injected precomputed values each time. This meant that in the "edge" case of not keeping edges, we were only succeeding by accident, because we never actually switched the evaluator to not keep edges. PiperOrigin-RevId: 173124505 --- .../build/lib/runtime/commands/InfoCommand.java | 62 +++++++++++----------- 1 file changed, 31 insertions(+), 31 deletions(-) (limited to 'src/main/java/com') diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java index 054f5ddff3..ca32232cc0 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.runtime.commands; import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.analysis.NoBuildEvent; @@ -106,37 +107,36 @@ public class InfoCommand implements BlazeCommand { Options infoOptions = optionsProvider.getOptions(Options.class); OutErr outErr = env.getReporter().getOutErr(); // Creating a BuildConfiguration is expensive and often unnecessary. Delay the creation until - // it is needed. - Supplier configurationSupplier = new Supplier() { - private BuildConfiguration configuration; - @Override - public BuildConfiguration get() { - if (configuration != null) { - return configuration; - } - try { - // In order to be able to answer configuration-specific queries, we need to setup the - // package path. Since info inherits all the build options, all the necessary information - // is available here. - env.setupPackageCache( - optionsProvider, runtime.getDefaultsPackageContent(optionsProvider)); - env.getSkyframeExecutor().setConfigurationFragmentFactories( - runtime.getConfigurationFragmentFactories()); - // TODO(bazel-team): What if there are multiple configurations? [multi-config] - return env.getSkyframeExecutor().getConfiguration( - env.getReporter(), runtime.createBuildOptions(optionsProvider), /*keepGoing=*/true); - } catch (InvalidConfigurationException e) { - env.getReporter().handle(Event.error(e.getMessage())); - throw new ExitCausingRuntimeException(ExitCode.COMMAND_LINE_ERROR); - } catch (AbruptExitException e) { - throw new ExitCausingRuntimeException("unknown error: " + e.getMessage(), - e.getExitCode()); - } catch (InterruptedException e) { - env.getReporter().handle(Event.error("interrupted")); - throw new ExitCausingRuntimeException(ExitCode.INTERRUPTED); - } - } - }; + // it is needed. We memoize so that it's cached intra-command (it's still created freshly on + // every command since the configuration can change across commands). + Supplier configurationSupplier = + Suppliers.memoize( + () -> { + try { + // In order to be able to answer configuration-specific queries, we need to set up + // the package path. Since info inherits all the build options, all the necessary + // information is available here. + env.setupPackageCache( + optionsProvider, runtime.getDefaultsPackageContent(optionsProvider)); + env.getSkyframeExecutor() + .setConfigurationFragmentFactories(runtime.getConfigurationFragmentFactories()); + // TODO(bazel-team): What if there are multiple configurations? [multi-config] + return env.getSkyframeExecutor() + .getConfiguration( + env.getReporter(), + runtime.createBuildOptions(optionsProvider), + /*keepGoing=*/ true); + } catch (InvalidConfigurationException e) { + env.getReporter().handle(Event.error(e.getMessage())); + throw new ExitCausingRuntimeException(ExitCode.COMMAND_LINE_ERROR); + } catch (AbruptExitException e) { + throw new ExitCausingRuntimeException( + "unknown error: " + e.getMessage(), e.getExitCode()); + } catch (InterruptedException e) { + env.getReporter().handle(Event.error("interrupted")); + throw new ExitCausingRuntimeException(ExitCode.INTERRUPTED); + } + }); Map items = getInfoItemMap(env, optionsProvider); -- cgit v1.2.3