Skip to content

Commit 47bef86

Browse files
lukesandbergcopybara-github
authored andcommitted
Gzip save files for multistage compilation
The save files scale linearly with the size of the application and can thus be quite large. By gzipping we can reduce sizes substantially, which should save disk space. Gzip is fairly fast and given that we can expect a reduction in file-io as a result this may or may not be a wall time regression. PiperOrigin-RevId: 511888713
1 parent 41daf94 commit 47bef86

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/com/google/javascript/jscomp/Compiler.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@
119119
import java.util.logging.Logger;
120120
import java.util.stream.Collectors;
121121
import java.util.stream.Stream;
122+
import java.util.zip.GZIPInputStream;
123+
import java.util.zip.GZIPOutputStream;
122124
import org.jspecify.nullness.Nullable;
123125

124126
/**
@@ -4035,12 +4037,16 @@ public void saveState(OutputStream outputStream) throws IOException {
40354037
runInCompilerThread(
40364038
() -> {
40374039
Tracer tracer = newTracer("serializeCompilerState");
4038-
new ObjectOutputStream(outputStream).writeObject(getCompilerState());
4040+
GZIPOutputStream gzipStream = new GZIPOutputStream(outputStream);
4041+
new ObjectOutputStream(gzipStream).writeObject(getCompilerState());
40394042
stopTracer(tracer, "serializeCompilerState");
40404043
tracer = newTracer("serializeTypedAst");
4041-
SerializeTypedAstPass.createFromOutputStream(this, outputStream)
4044+
SerializeTypedAstPass.createFromOutputStream(this, gzipStream)
40424045
.process(externsRoot, jsRoot);
40434046
stopTracer(tracer, "serializeTypedAst");
4047+
// Finish will flush all zip buffers and write out zip trailing bytes but it will not
4048+
// close the stream since that is our callers responsibility.
4049+
gzipStream.finish();
40444050
return null;
40454051
});
40464052
}
@@ -4059,7 +4065,7 @@ public void restoreState(InputStream inputStream) throws IOException, ClassNotFo
40594065
Tracer tracer = newTracer(PassNames.DESERIALIZE_COMPILER_STATE);
40604066
logger.fine("Deserializing the CompilerState");
40614067
try {
4062-
deserializeCompilerState(inputStream);
4068+
deserializeCompilerState(new GZIPInputStream(inputStream));
40634069
return null;
40644070
} finally {
40654071
logger.fine("Finished deserializing CompilerState");

0 commit comments

Comments
 (0)