Skip to content

Commit

Permalink
Mitigate GC churn in module map file writes: No need to pin entire co…
Browse files Browse the repository at this point in the history
…ntents in memory. Instead, write to the output stream incrementally.

PiperOrigin-RevId: 159046844
  • Loading branch information
ericfelly authored and meteorcloudy committed Jun 16, 2017
1 parent 8570e4d commit e17f8af
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.devtools.build.lib.vfs.PathFragment;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -98,7 +99,7 @@ public DeterministicWriter newDeterministicWriter(ActionExecutionContext ctx) {
return new DeterministicWriter() {
@Override
public void writeOutputFile(OutputStream out) throws IOException {
StringBuilder content = new StringBuilder();
OutputStreamWriter content = new OutputStreamWriter(out, StandardCharsets.ISO_8859_1);
PathFragment fragment = cppModuleMap.getArtifact().getExecPath();
int segmentsToExecPath = fragment.segmentCount() - 1;
Optional<Artifact> umbrellaHeader = cppModuleMap.getUmbrellaHeader();
Expand Down Expand Up @@ -162,11 +163,11 @@ public void writeOutputFile(OutputStream out) throws IOException {
.append(dep.getName())
.append("\" \"")
.append(leadingPeriods)
.append(dep.getArtifact().getExecPath())
.append(dep.getArtifact().getExecPathString())
.append("\"");
}
}
out.write(content.toString().getBytes(StandardCharsets.ISO_8859_1));
content.flush();
}
};
}
Expand All @@ -185,9 +186,9 @@ private static Iterable<Artifact> expandedHeaders(ArtifactExpander artifactExpan
return ImmutableList.copyOf(expandedHeaders);
}

private void appendHeader(StringBuilder content, String visibilitySpecifier, PathFragment path,
String leadingPeriods, boolean canCompile, HashSet<PathFragment> deduper,
boolean isUmbrellaHeader) {
private void appendHeader(Appendable content, String visibilitySpecifier,
PathFragment path, String leadingPeriods, boolean canCompile, HashSet<PathFragment> deduper,
boolean isUmbrellaHeader) throws IOException {
if (deduper.contains(path)) {
return;
}
Expand All @@ -197,7 +198,7 @@ private void appendHeader(StringBuilder content, String visibilitySpecifier, Pat
return;
}
if (generateSubmodules) {
content.append(" module \"").append(path).append("\" {\n");
content.append(" module \"").append(path.toString()).append("\" {\n");
content.append(" export *\n ");
}
content.append(" ");
Expand All @@ -207,7 +208,7 @@ private void appendHeader(StringBuilder content, String visibilitySpecifier, Pat
if (!canCompile || !shouldCompileHeader(path)) {
content.append("textual ");
}
content.append("header \"").append(leadingPeriods).append(path).append("\"");
content.append("header \"").append(leadingPeriods).append(path.toString()).append("\"");
if (generateSubmodules) {
content.append("\n }");
}
Expand Down

0 comments on commit e17f8af

Please sign in to comment.