Skip to content

Commit

Permalink
Intern all strings in proto messages in the query summary.
Browse files Browse the repository at this point in the history
When parsing the query output, or de=serializing a query summary proto, pass all protos through a proto string interner. This elimiates duplicate string instances in memory and reduces memory usage.

PiperOrigin-RevId: 612836541
  • Loading branch information
Googler authored and copybara-github committed Mar 5, 2024
1 parent 08b7b3a commit de21dc1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions querysync/java/com/google/idea/blaze/qsync/query/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ java_library(
deps = [
":querysummary_java_proto",
"//shared",
"//shared:proto",
"//third_party/auto_value",
"//third_party/bazel/src/main/protobuf:build_java_proto",
"@com_google_guava_guava//jar",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.google.devtools.build.lib.query2.proto.proto2api.Build;
import com.google.devtools.build.lib.query2.proto.proto2api.Build.Target;
import com.google.idea.blaze.common.Label;
import com.google.idea.blaze.common.proto.ProtoStringInterner;
import com.google.idea.blaze.qsync.query.Query.SourceFile;
import java.io.BufferedInputStream;
import java.io.File;
Expand Down Expand Up @@ -135,7 +136,8 @@ public static QuerySummary create(InputStream protoInputStream) throws IOExcepti
Map<String, Query.Rule> ruleMap = Maps.newHashMap();
Set<String> packagesWithErrors = Sets.newHashSet();
Build.Target target;
while ((target = Target.parseDelimitedFrom(protoInputStream)) != null) {
ProtoStringInterner interner = new ProtoStringInterner();
while ((target = interner.intern(Target.parseDelimitedFrom(protoInputStream))) != null) {
switch (target.getType()) {
case SOURCE_FILE:
Query.SourceFile sourceFile =
Expand Down Expand Up @@ -335,7 +337,8 @@ public Builder putAllPackagesWithErrors(Set<Path> packagesWithErrors) {
}

public QuerySummary build() {
return QuerySummary.create(builder.build());
ProtoStringInterner interner = new ProtoStringInterner();
return QuerySummary.create(interner.intern(builder.build()));
}
}
}

0 comments on commit de21dc1

Please sign in to comment.