aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools
diff options
context:
space:
mode:
authorGravatar Nathan Harmata <nharmata@google.com>2016-04-29 22:17:00 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-05-02 09:10:07 +0000
commitdd61520f48cb5fcc28df374e8f7c4c05f68f18a0 (patch)
treefe62e67b8d28e582879b2053920b7ddccc3fafd3 /src/main/java/com/google/devtools
parent19350de0caaafbe3c6800c09d520d3ced82d87f9 (diff)
When we don't have an OutputService, precompute and cache the assumed-to-be-immutable filesystem type of output_base.
When we do have an OutputService, defer computation of the OutputService's dynamic filesystem type until we actually need it at the start of a "build" or "test" command. This saves ~450us on each invocation, according to my benchmarks. -- MOS_MIGRATED_REVID=121156323
Diffstat (limited to 'src/main/java/com/google/devtools')
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/BlazeWorkspace.java14
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java25
3 files changed, 24 insertions, 17 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java b/src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java
index f04eab4f96..182b74cd14 100644
--- a/src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java
+++ b/src/main/java/com/google/devtools/build/lib/buildtool/BuildTool.java
@@ -152,7 +152,7 @@ public final class BuildTool {
BuildConfigurationCollection configurations = null;
boolean catastrophe = false;
try {
- env.getEventBus().post(new BuildStartingEvent(env.getOutputFileSystem(), request));
+ env.getEventBus().post(new BuildStartingEvent(env.determineOutputFileSystem(), request));
LOG.info("Build identifier: " + request.getId());
executionTool = new ExecutionTool(env, request);
if (needsExecutionPhase(request.getBuildOptions())) {
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeWorkspace.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeWorkspace.java
index aa98d3b98a..6652bd74ab 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeWorkspace.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeWorkspace.java
@@ -69,6 +69,8 @@ public final class BlazeWorkspace {
@Nullable
private Range<Long> lastExecutionRange = null;
+ private final String outputBaseFilesystemTypeName;
+
public BlazeWorkspace(BlazeRuntime runtime, BlazeDirectories directories,
SkyframeExecutor skyframeExecutor, SubscriberExceptionHandler eventBusExceptionHandler,
WorkspaceStatusAction.Factory workspaceStatusActionFactory, BinTools binTools) {
@@ -85,6 +87,9 @@ public final class BlazeWorkspace {
writeDoNotBuildHereFile(runtime.getStartupOptionsProvider());
}
setupExecRoot();
+ // Here we use outputBase instead of outputPath because we need a file system to create the
+ // latter.
+ this.outputBaseFilesystemTypeName = FileSystemUtils.getFileSystem(getOutputBase());
}
/**
@@ -126,6 +131,15 @@ public final class BlazeWorkspace {
}
/**
+ * Returns the cached value of
+ * {@code getOutputBase().getFilesystem().getFileSystemType(getOutputBase())}, which is assumed
+ * to be constant for a fixed workspace for the life of the Blaze server.
+ */
+ public String getOutputBaseFilesystemTypeName() {
+ return outputBaseFilesystemTypeName;
+ }
+
+ /**
* Returns the output path associated with this Blaze server process..
*/
public Path getOutputPath() {
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java b/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java
index 0900086aca..38eac7f230 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java
@@ -87,7 +87,6 @@ public final class CommandEnvironment {
private PathFragment relativeWorkingDirectory = PathFragment.EMPTY_FRAGMENT;
private long commandStartTime;
private OutputService outputService;
- private String outputFileSystem;
private Path workingDirectory;
private AtomicReference<AbruptExitException> pendingException = new AtomicReference<>();
@@ -413,10 +412,6 @@ public final class CommandEnvironment {
this.workingDirectory = workingDirectory;
}
- public String getOutputFileSystem() {
- return outputFileSystem;
- }
-
/**
* Hook method called by the BlazeCommandDispatcher prior to the dispatch of
* each command.
@@ -450,8 +445,6 @@ public final class CommandEnvironment {
SkyframeExecutor skyframeExecutor = getSkyframeExecutor();
skyframeExecutor.setOutputService(outputService);
- this.outputFileSystem = determineOutputFileSystem();
-
// Ensure that the working directory will be under the workspace directory.
Path workspace = getWorkspace();
Path workingDirectory;
@@ -507,16 +500,16 @@ public final class CommandEnvironment {
new CommandStartEvent(command.name(), commandId, getClientEnv(), workingDirectory));
}
- /**
- * Figures out what file system we are writing output to. Here we use
- * outputBase instead of outputPath because we need a file system to create the latter.
- */
- private String determineOutputFileSystem() {
+ /** Returns the name of the file system we are writing output to. */
+ public String determineOutputFileSystem() {
+ // If we have a fancy OutputService, this may be different between consecutive Blaze commands
+ // and so we need to compute it freshly. Otherwise, we can used the immutable value that's
+ // precomputed by our BlazeWorkspace.
if (getOutputService() != null) {
- return getOutputService().getFilesSystemName();
- }
- try (AutoProfiler p = profiled("Finding output file system", ProfilerTask.INFO)) {
- return FileSystemUtils.getFileSystem(getOutputBase());
+ try (AutoProfiler p = profiled("Finding output file system", ProfilerTask.INFO)) {
+ return getOutputService().getFilesSystemName();
+ }
}
+ return workspace.getOutputBaseFilesystemTypeName();
}
}