diff options
author | Googler <noreply@google.com> | 2016-08-16 20:41:22 +0000 |
---|---|---|
committer | Philipp Wollermann <philwo@google.com> | 2016-08-17 11:26:33 +0000 |
commit | d1910c35673123654b251af478320cf05a96d9e0 (patch) | |
tree | c5d5aaf6fc96eba2ff80a14130e8f4022b518bfc /src/tools/android/java/com/google/devtools/build/android/xml | |
parent | 2f36f313b9d10e89611207422a4271f733fe49df (diff) |
Share source paths for more compact res proto serialization
Source abs paths can be pretty long. If a value
file like colors.xml has N resources then we
serialize the path N times. Instead, make a
table and just serialize the index. Can reduce
resource proto sizes from X to 0.65*X. in some
experiments. CPU instructions executed is slightly
lower, but critical path impact is pretty minimal
since parsing happens in parallel anyway.
This doesn't help with drawables (path only shows
up once) but doesn't really hurt (an extra index
number). I tried sharing the root (a table of the
res dirs). That can be another 10%, and helps with
the drawable case. However, a naive enumeration
of roots (src.getParent().getParent()) added *much*
more overhead to the writing stage, so I didn't
go on with that.
--
MOS_MIGRATED_REVID=130440810
Diffstat (limited to 'src/tools/android/java/com/google/devtools/build/android/xml')
8 files changed, 16 insertions, 16 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/xml/ArrayXmlResourceValue.java b/src/tools/android/java/com/google/devtools/build/android/xml/ArrayXmlResourceValue.java index 46a382f5bb..f9cfd6a332 100644 --- a/src/tools/android/java/com/google/devtools/build/android/xml/ArrayXmlResourceValue.java +++ b/src/tools/android/java/com/google/devtools/build/android/xml/ArrayXmlResourceValue.java @@ -138,11 +138,11 @@ public class ArrayXmlResourceValue implements XmlResourceValue { } @Override - public int serializeTo(Path source, Namespaces namespaces, OutputStream output) + public int serializeTo(int sourceId, Namespaces namespaces, OutputStream output) throws IOException { return XmlResourceValues.serializeProtoDataValue( output, - XmlResourceValues.newSerializableDataValueBuilder(source) + XmlResourceValues.newSerializableDataValueBuilder(sourceId) .setXmlValue( SerializeFormat.DataValueXml.newBuilder() .addAllListValue(values) diff --git a/src/tools/android/java/com/google/devtools/build/android/xml/AttrXmlResourceValue.java b/src/tools/android/java/com/google/devtools/build/android/xml/AttrXmlResourceValue.java index dc8968cb12..c19c3be45c 100644 --- a/src/tools/android/java/com/google/devtools/build/android/xml/AttrXmlResourceValue.java +++ b/src/tools/android/java/com/google/devtools/build/android/xml/AttrXmlResourceValue.java @@ -343,10 +343,10 @@ public class AttrXmlResourceValue implements XmlResourceValue { @SuppressWarnings("deprecation") @Override - public int serializeTo(Path source, Namespaces namespaces, OutputStream output) + public int serializeTo(int sourceId, Namespaces namespaces, OutputStream output) throws IOException { SerializeFormat.DataValue.Builder builder = - XmlResourceValues.newSerializableDataValueBuilder(source); + XmlResourceValues.newSerializableDataValueBuilder(sourceId); SerializeFormat.DataValueXml.Builder xmlValueBuilder = SerializeFormat.DataValueXml.newBuilder(); xmlValueBuilder diff --git a/src/tools/android/java/com/google/devtools/build/android/xml/IdXmlResourceValue.java b/src/tools/android/java/com/google/devtools/build/android/xml/IdXmlResourceValue.java index d9a36488e6..ec870d31b5 100644 --- a/src/tools/android/java/com/google/devtools/build/android/xml/IdXmlResourceValue.java +++ b/src/tools/android/java/com/google/devtools/build/android/xml/IdXmlResourceValue.java @@ -87,7 +87,7 @@ public class IdXmlResourceValue implements XmlResourceValue { } @Override - public int serializeTo(Path source, Namespaces namespaces, OutputStream output) + public int serializeTo(int sourceId, Namespaces namespaces, OutputStream output) throws IOException { Builder xmlValue = SerializeFormat.DataValueXml.newBuilder() @@ -97,7 +97,7 @@ public class IdXmlResourceValue implements XmlResourceValue { xmlValue.setValue(value); } SerializeFormat.DataValue dataValue = - XmlResourceValues.newSerializableDataValueBuilder(source).setXmlValue(xmlValue).build(); + XmlResourceValues.newSerializableDataValueBuilder(sourceId).setXmlValue(xmlValue).build(); dataValue.writeDelimitedTo(output); return CodedOutputStream.computeUInt32SizeNoTag(dataValue.getSerializedSize()) + dataValue.getSerializedSize(); diff --git a/src/tools/android/java/com/google/devtools/build/android/xml/PluralXmlResourceValue.java b/src/tools/android/java/com/google/devtools/build/android/xml/PluralXmlResourceValue.java index a8e92e4b19..7649117f05 100644 --- a/src/tools/android/java/com/google/devtools/build/android/xml/PluralXmlResourceValue.java +++ b/src/tools/android/java/com/google/devtools/build/android/xml/PluralXmlResourceValue.java @@ -133,10 +133,10 @@ public class PluralXmlResourceValue implements XmlResourceValue { } @Override - public int serializeTo(Path source, Namespaces namespaces, OutputStream output) + public int serializeTo(int sourceId, Namespaces namespaces, OutputStream output) throws IOException { SerializeFormat.DataValue.Builder builder = - XmlResourceValues.newSerializableDataValueBuilder(source); + XmlResourceValues.newSerializableDataValueBuilder(sourceId); SerializeFormat.DataValue value = builder .setXmlValue( diff --git a/src/tools/android/java/com/google/devtools/build/android/xml/PublicXmlResourceValue.java b/src/tools/android/java/com/google/devtools/build/android/xml/PublicXmlResourceValue.java index ec6aa91c41..9a0308dc7c 100644 --- a/src/tools/android/java/com/google/devtools/build/android/xml/PublicXmlResourceValue.java +++ b/src/tools/android/java/com/google/devtools/build/android/xml/PublicXmlResourceValue.java @@ -134,7 +134,7 @@ public class PublicXmlResourceValue implements XmlResourceValue { } @Override - public int serializeTo(Path source, Namespaces namespaces, OutputStream output) + public int serializeTo(int sourceId, Namespaces namespaces, OutputStream output) throws IOException { Map<String, String> assignments = Maps.newLinkedHashMapWithExpectedSize(typeToId.size()); for (Entry<ResourceType, Optional<Integer>> entry : typeToId.entrySet()) { @@ -143,7 +143,7 @@ public class PublicXmlResourceValue implements XmlResourceValue { assignments.put(entry.getKey().toString(), stringValue); } SerializeFormat.DataValue.Builder builder = - XmlResourceValues.newSerializableDataValueBuilder(source); + XmlResourceValues.newSerializableDataValueBuilder(sourceId); builder.setXmlValue( builder .getXmlValueBuilder() diff --git a/src/tools/android/java/com/google/devtools/build/android/xml/SimpleXmlResourceValue.java b/src/tools/android/java/com/google/devtools/build/android/xml/SimpleXmlResourceValue.java index bc7c44a3f0..d6442a9e63 100644 --- a/src/tools/android/java/com/google/devtools/build/android/xml/SimpleXmlResourceValue.java +++ b/src/tools/android/java/com/google/devtools/build/android/xml/SimpleXmlResourceValue.java @@ -218,10 +218,10 @@ public class SimpleXmlResourceValue implements XmlResourceValue { } @Override - public int serializeTo(Path source, Namespaces namespaces, OutputStream output) + public int serializeTo(int sourceId, Namespaces namespaces, OutputStream output) throws IOException { SerializeFormat.DataValue.Builder builder = - XmlResourceValues.newSerializableDataValueBuilder(source); + XmlResourceValues.newSerializableDataValueBuilder(sourceId); Builder xmlValueBuilder = builder .getXmlValueBuilder() diff --git a/src/tools/android/java/com/google/devtools/build/android/xml/StyleXmlResourceValue.java b/src/tools/android/java/com/google/devtools/build/android/xml/StyleXmlResourceValue.java index 1bd20dab77..e539c98e5c 100644 --- a/src/tools/android/java/com/google/devtools/build/android/xml/StyleXmlResourceValue.java +++ b/src/tools/android/java/com/google/devtools/build/android/xml/StyleXmlResourceValue.java @@ -112,7 +112,7 @@ public class StyleXmlResourceValue implements XmlResourceValue { } @Override - public int serializeTo(Path source, Namespaces namespaces, OutputStream output) + public int serializeTo(int sourceId, Namespaces namespaces, OutputStream output) throws IOException { SerializeFormat.DataValueXml.Builder xmlValueBuilder = SerializeFormat.DataValueXml.newBuilder() @@ -124,7 +124,7 @@ public class StyleXmlResourceValue implements XmlResourceValue { } return XmlResourceValues.serializeProtoDataValue( output, - XmlResourceValues.newSerializableDataValueBuilder(source).setXmlValue(xmlValueBuilder)); + XmlResourceValues.newSerializableDataValueBuilder(sourceId).setXmlValue(xmlValueBuilder)); } @Override diff --git a/src/tools/android/java/com/google/devtools/build/android/xml/StyleableXmlResourceValue.java b/src/tools/android/java/com/google/devtools/build/android/xml/StyleableXmlResourceValue.java index d37e34d5b0..822b43e9d4 100644 --- a/src/tools/android/java/com/google/devtools/build/android/xml/StyleableXmlResourceValue.java +++ b/src/tools/android/java/com/google/devtools/build/android/xml/StyleableXmlResourceValue.java @@ -143,11 +143,11 @@ public class StyleableXmlResourceValue implements XmlResourceValue { } @Override - public int serializeTo(Path source, Namespaces namespaces, OutputStream output) + public int serializeTo(int sourceId, Namespaces namespaces, OutputStream output) throws IOException { return XmlResourceValues.serializeProtoDataValue( output, - XmlResourceValues.newSerializableDataValueBuilder(source) + XmlResourceValues.newSerializableDataValueBuilder(sourceId) .setXmlValue( SerializeFormat.DataValueXml.newBuilder() .setType(XmlType.STYLEABLE) |