Skip to content

Commit

Permalink
Add a flag to disable execution log sorting.
Browse files Browse the repository at this point in the history
This may improve performance when the execution log gets very large. The default is still to sort, so this is a backwards-compatible change.

Closes bazelbuild#17354.
Closes bazelbuild#17111.

PiperOrigin-RevId: 509822315
Change-Id: If948ec4a933389b6f8405985813dd76c549c445c
  • Loading branch information
YuanHao97 authored and copybara-github committed Feb 15, 2023
1 parent 72f0045 commit 1a6ffe6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/lib/bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ java_library(
"//src/main/java/com/google/devtools/build/lib/util/io",
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/protobuf:failure_details_java_proto",
"//src/main/protobuf:spawn_java_proto",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.devtools.build.lib.exec.ExecutionOptions;
import com.google.devtools.build.lib.exec.ExecutorBuilder;
import com.google.devtools.build.lib.exec.ModuleActionContextRegistry;
import com.google.devtools.build.lib.exec.Protos.SpawnExec;
import com.google.devtools.build.lib.exec.SpawnLogContext;
import com.google.devtools.build.lib.remote.options.RemoteOptions;
import com.google.devtools.build.lib.runtime.BlazeModule;
Expand Down Expand Up @@ -162,7 +163,14 @@ public void afterCommand() throws AbruptExitException {
spawnLogContext.close();
if (!outputStreams.isEmpty()) {
InputStream in = rawOutput.getInputStream();
StableSort.stableSort(in, outputStreams);
if (spawnLogContext.shouldSort()) {
StableSort.stableSort(in, outputStreams);
} else {
while (in.available() > 0) {
SpawnExec ex = SpawnExec.parseDelimitedFrom(in);
outputStreams.write(ex);
}
}
outputStreams.close();
}
done = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,17 @@ public boolean usingLocalTestJobs() {
+ " --subcommands (for displaying subcommands in terminal output).")
public PathFragment executionLogJsonFile;

@Option(
name = "execution_log_sort",
defaultValue = "true",
documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
effectTags = {OptionEffectTag.UNKNOWN},
help =
"Whether to sort the execution log. Set to false to improve memory"
+ " performance, at the cost of producing the log in nondeterministic"
+ " order.")
public boolean executionLogSort;

@Option(
name = "experimental_split_xml_generation",
defaultValue = "true",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,8 @@ private Digest computeDigest(
.setSizeBytes(fileSize)
.build();
}

public boolean shouldSort() {
return executionOptions.executionLogSort;
}
}

0 comments on commit 1a6ffe6

Please sign in to comment.