Skip to content

Commit

Permalink
Merge pull request #128 from sayjeyhi/fix/sayjeyhi/huge-bundle-size
Browse files Browse the repository at this point in the history
Fix: reduce huge bundle size by adding ADVANCED_OPTIMIZATIONS when compiling protobuf JS
  • Loading branch information
dibenede authored Sep 28, 2022
2 parents b545ac8 + 7aed33b commit f9b1939
Show file tree
Hide file tree
Showing 13 changed files with 2,651 additions and 70 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.idea
/node_modules/
commonjs_out
google/protobuf
bazel-*
/deps.js
/testproto_libs1.js
/testproto_libs2.js
/google-protobuf.js
36 changes: 36 additions & 0 deletions binary/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ jspb.BinaryReader.prototype.getBuffer = function() {
/**
* @return {number} The field number of the next field in the buffer, or
* INVALID_FIELD_NUMBER if there is no next field.
* @export
*/
jspb.BinaryReader.prototype.getFieldNumber = function() {
return this.nextField_;
Expand All @@ -210,6 +211,7 @@ jspb.BinaryReader.prototype.getWireType = function() {
/**
* @return {boolean} Whether the current wire type is a delimited field. Used to
* conditionally parse packed repeated fields.
* @export
*/
jspb.BinaryReader.prototype.isDelimited = function() {
return this.nextWireType_ == jspb.BinaryConstants.WireType.DELIMITED;
Expand All @@ -219,6 +221,7 @@ jspb.BinaryReader.prototype.isDelimited = function() {
/**
* @return {boolean} Whether the current wire type is an end-group tag. Used as
* an exit condition in decoder loops in generated code.
* @export
*/
jspb.BinaryReader.prototype.isEndGroup = function() {
return this.nextWireType_ == jspb.BinaryConstants.WireType.END_GROUP;
Expand Down Expand Up @@ -272,6 +275,7 @@ jspb.BinaryReader.prototype.advance = function(count) {
* we saw a valid field header or false if we've read the whole stream.
* Throws an error if we encountered a deprecated START_GROUP/END_GROUP field.
* @return {boolean} True if the stream contains more fields.
* @export
*/
jspb.BinaryReader.prototype.nextField = function() {
// If we're at the end of the block, there are no more fields.
Expand Down Expand Up @@ -541,6 +545,7 @@ jspb.BinaryReader.prototype.readAny = function(fieldType) {
* @template T
* @param {T} message
* @param {function(T, !jspb.BinaryReader)} reader
* @export
*/
jspb.BinaryReader.prototype.readMessage = function(message, reader) {
goog.asserts.assert(
Expand Down Expand Up @@ -570,6 +575,7 @@ jspb.BinaryReader.prototype.readMessage = function(message, reader) {
* @param {number} field
* @param {T} message
* @param {function(T, !jspb.BinaryReader)} reader
* @export
*/
jspb.BinaryReader.prototype.readGroup =
function(field, message, reader) {
Expand Down Expand Up @@ -614,6 +620,7 @@ jspb.BinaryReader.prototype.getFieldDecoder = function() {
* error if the next field in the stream is not of the correct wire type.
*
* @return {number} The value of the signed 32-bit integer field.
* @export
*/
jspb.BinaryReader.prototype.readInt32 = function() {
goog.asserts.assert(
Expand Down Expand Up @@ -643,6 +650,7 @@ jspb.BinaryReader.prototype.readInt32String = function() {
* error if the next field in the stream is not of the correct wire type.
*
* @return {number} The value of the signed 64-bit integer field.
* @export
*/
jspb.BinaryReader.prototype.readInt64 = function() {
goog.asserts.assert(
Expand Down Expand Up @@ -672,6 +680,7 @@ jspb.BinaryReader.prototype.readInt64String = function() {
* error if the next field in the stream is not of the correct wire type.
*
* @return {number} The value of the unsigned 32-bit integer field.
* @export
*/
jspb.BinaryReader.prototype.readUint32 = function() {
goog.asserts.assert(
Expand Down Expand Up @@ -701,6 +710,7 @@ jspb.BinaryReader.prototype.readUint32String = function() {
* error if the next field in the stream is not of the correct wire type.
*
* @return {number} The value of the unsigned 64-bit integer field.
* @export
*/
jspb.BinaryReader.prototype.readUint64 = function() {
goog.asserts.assert(
Expand Down Expand Up @@ -731,6 +741,7 @@ jspb.BinaryReader.prototype.readUint64String = function() {
* wire type.
*
* @return {number} The value of the signed 32-bit integer field.
* @export
*/
jspb.BinaryReader.prototype.readSint32 = function() {
goog.asserts.assert(
Expand All @@ -745,6 +756,7 @@ jspb.BinaryReader.prototype.readSint32 = function() {
* wire type.
*
* @return {number} The value of the signed 64-bit integer field.
* @export
*/
jspb.BinaryReader.prototype.readSint64 = function() {
goog.asserts.assert(
Expand Down Expand Up @@ -773,6 +785,7 @@ jspb.BinaryReader.prototype.readSint64String = function() {
* wire type.
*
* @return {number} The value of the double field.
* @export
*/
jspb.BinaryReader.prototype.readFixed32 = function() {
goog.asserts.assert(
Expand All @@ -787,6 +800,7 @@ jspb.BinaryReader.prototype.readFixed32 = function() {
* wire type.
*
* @return {number} The value of the float field.
* @export
*/
jspb.BinaryReader.prototype.readFixed64 = function() {
goog.asserts.assert(
Expand Down Expand Up @@ -818,6 +832,7 @@ jspb.BinaryReader.prototype.readFixed64String = function() {
* type.
*
* @return {number} The value of the signed 32-bit integer field.
* @export
*/
jspb.BinaryReader.prototype.readSfixed32 = function() {
goog.asserts.assert(
Expand Down Expand Up @@ -847,6 +862,7 @@ jspb.BinaryReader.prototype.readSfixed32String = function() {
* type.
*
* @return {number} The value of the sfixed64 field.
* @export
*/
jspb.BinaryReader.prototype.readSfixed64 = function() {
goog.asserts.assert(
Expand Down Expand Up @@ -876,6 +892,7 @@ jspb.BinaryReader.prototype.readSfixed64String = function() {
* error if the next field in the stream is not of the correct wire type.
*
* @return {number} The value of the float field.
* @export
*/
jspb.BinaryReader.prototype.readFloat = function() {
goog.asserts.assert(
Expand All @@ -889,6 +906,7 @@ jspb.BinaryReader.prototype.readFloat = function() {
* error if the next field in the stream is not of the correct wire type.
*
* @return {number} The value of the double field.
* @export
*/
jspb.BinaryReader.prototype.readDouble = function() {
goog.asserts.assert(
Expand All @@ -902,6 +920,7 @@ jspb.BinaryReader.prototype.readDouble = function() {
* field in the stream is not of the correct wire type.
*
* @return {boolean} The value of the boolean field.
* @export
*/
jspb.BinaryReader.prototype.readBool = function() {
goog.asserts.assert(
Expand All @@ -915,6 +934,7 @@ jspb.BinaryReader.prototype.readBool = function() {
* field in the stream is not of the correct wire type.
*
* @return {number} The value of the enum field.
* @export
*/
jspb.BinaryReader.prototype.readEnum = function() {
goog.asserts.assert(
Expand All @@ -928,6 +948,7 @@ jspb.BinaryReader.prototype.readEnum = function() {
* field in the stream is not of the correct wire type.
*
* @return {string} The value of the string field.
* @export
*/
jspb.BinaryReader.prototype.readString = function() {
goog.asserts.assert(
Expand All @@ -942,6 +963,7 @@ jspb.BinaryReader.prototype.readString = function() {
* null if the next field in the stream has an invalid length value.
*
* @return {!Uint8Array} The block of bytes.
* @export
*/
jspb.BinaryReader.prototype.readBytes = function() {
goog.asserts.assert(
Expand Down Expand Up @@ -1070,6 +1092,7 @@ jspb.BinaryReader.prototype.readPackedField_ = function(decodeMethod) {
* Reads a packed int32 field, which consists of a length header and a list of
* signed varints.
* @return {!Array<number>}
* @export
*/
jspb.BinaryReader.prototype.readPackedInt32 = function() {
return this.readPackedField_(this.decoder_.readSignedVarint32);
Expand All @@ -1090,6 +1113,7 @@ jspb.BinaryReader.prototype.readPackedInt32String = function() {
* Reads a packed int64 field, which consists of a length header and a list of
* signed varints.
* @return {!Array<number>}
* @export
*/
jspb.BinaryReader.prototype.readPackedInt64 = function() {
return this.readPackedField_(this.decoder_.readSignedVarint64);
Expand All @@ -1110,6 +1134,7 @@ jspb.BinaryReader.prototype.readPackedInt64String = function() {
* Reads a packed uint32 field, which consists of a length header and a list of
* unsigned varints.
* @return {!Array<number>}
* @export
*/
jspb.BinaryReader.prototype.readPackedUint32 = function() {
return this.readPackedField_(this.decoder_.readUnsignedVarint32);
Expand All @@ -1130,6 +1155,7 @@ jspb.BinaryReader.prototype.readPackedUint32String = function() {
* Reads a packed uint64 field, which consists of a length header and a list of
* unsigned varints.
* @return {!Array<number>}
* @export
*/
jspb.BinaryReader.prototype.readPackedUint64 = function() {
return this.readPackedField_(this.decoder_.readUnsignedVarint64);
Expand All @@ -1150,6 +1176,7 @@ jspb.BinaryReader.prototype.readPackedUint64String = function() {
* Reads a packed sint32 field, which consists of a length header and a list of
* zigzag varints.
* @return {!Array<number>}
* @export
*/
jspb.BinaryReader.prototype.readPackedSint32 = function() {
return this.readPackedField_(this.decoder_.readZigzagVarint32);
Expand All @@ -1160,6 +1187,7 @@ jspb.BinaryReader.prototype.readPackedSint32 = function() {
* Reads a packed sint64 field, which consists of a length header and a list of
* zigzag varints.
* @return {!Array<number>}
* @export
*/
jspb.BinaryReader.prototype.readPackedSint64 = function() {
return this.readPackedField_(this.decoder_.readZigzagVarint64);
Expand All @@ -1180,6 +1208,7 @@ jspb.BinaryReader.prototype.readPackedSint64String = function() {
* Reads a packed fixed32 field, which consists of a length header and a list
* of unsigned 32-bit ints.
* @return {!Array<number>}
* @export
*/
jspb.BinaryReader.prototype.readPackedFixed32 = function() {
return this.readPackedField_(this.decoder_.readUint32);
Expand All @@ -1190,6 +1219,7 @@ jspb.BinaryReader.prototype.readPackedFixed32 = function() {
* Reads a packed fixed64 field, which consists of a length header and a list
* of unsigned 64-bit ints.
* @return {!Array<number>}
* @export
*/
jspb.BinaryReader.prototype.readPackedFixed64 = function() {
return this.readPackedField_(this.decoder_.readUint64);
Expand All @@ -1210,6 +1240,7 @@ jspb.BinaryReader.prototype.readPackedFixed64String = function() {
* Reads a packed sfixed32 field, which consists of a length header and a list
* of 32-bit ints.
* @return {!Array<number>}
* @export
*/
jspb.BinaryReader.prototype.readPackedSfixed32 = function() {
return this.readPackedField_(this.decoder_.readInt32);
Expand All @@ -1220,6 +1251,7 @@ jspb.BinaryReader.prototype.readPackedSfixed32 = function() {
* Reads a packed sfixed64 field, which consists of a length header and a list
* of 64-bit ints.
* @return {!Array<number>}
* @export
*/
jspb.BinaryReader.prototype.readPackedSfixed64 = function() {
return this.readPackedField_(this.decoder_.readInt64);
Expand All @@ -1240,6 +1272,7 @@ jspb.BinaryReader.prototype.readPackedSfixed64String = function() {
* Reads a packed float field, which consists of a length header and a list of
* floats.
* @return {!Array<number>}
* @export
*/
jspb.BinaryReader.prototype.readPackedFloat = function() {
return this.readPackedField_(this.decoder_.readFloat);
Expand All @@ -1250,6 +1283,7 @@ jspb.BinaryReader.prototype.readPackedFloat = function() {
* Reads a packed double field, which consists of a length header and a list of
* doubles.
* @return {!Array<number>}
* @export
*/
jspb.BinaryReader.prototype.readPackedDouble = function() {
return this.readPackedField_(this.decoder_.readDouble);
Expand All @@ -1260,6 +1294,7 @@ jspb.BinaryReader.prototype.readPackedDouble = function() {
* Reads a packed bool field, which consists of a length header and a list of
* unsigned varints.
* @return {!Array<boolean>}
* @export
*/
jspb.BinaryReader.prototype.readPackedBool = function() {
return this.readPackedField_(this.decoder_.readBool);
Expand All @@ -1270,6 +1305,7 @@ jspb.BinaryReader.prototype.readPackedBool = function() {
* Reads a packed enum field, which consists of a length header and a list of
* unsigned varints.
* @return {!Array<number>}
* @export
*/
jspb.BinaryReader.prototype.readPackedEnum = function() {
return this.readPackedField_(this.decoder_.readEnum);
Expand Down
Loading

0 comments on commit f9b1939

Please sign in to comment.