protobuf.js version: 6.6.5 (but also on master)
When generating code, there is this piece:
const $types = {
3: "xyz.MyEnum"
}; $lazyTypes.push($types);
which is then resolved later in util.lazyResolve. I am trying to use protobuf.js in the Things Network Console which allows you to specify a payload function to decode incoming data from a byte buffer. This code is run within otto, so I am trying to get a statically generated decoder as small as possible. With Uglify I get to 22KB for a decode/fromObject/toObject combo (17.4 for decode-only). However, the Google Closure Compiler is far better at getting this even smaller with advanced optimizations (about 12KB). One problem with that, however, is that it renames symbols quite rigidly, so xyz.MyEnum would be renamed and when the lazy loader tries to find it, it won't be there any more.
There are a couple of possible solutions I can see for this. We could either define the types as callbacks, e.g.
const $types = {
3: () => xyz.MyEnum
}; $lazyTypes.push($types);
or we can define them with array notation:
xyz["MyEnum"]= (function() {...}
to prevent them from being modified. Is there a reason why on a static build these are lazily evaluated at all?
protobuf.js version: 6.6.5 (but also on master)
When generating code, there is this piece:
which is then resolved later in
util.lazyResolve. I am trying to use protobuf.js in the Things Network Console which allows you to specify a payload function to decode incoming data from a byte buffer. This code is run within otto, so I am trying to get a statically generated decoder as small as possible. With Uglify I get to 22KB for a decode/fromObject/toObject combo (17.4 for decode-only). However, the Google Closure Compiler is far better at getting this even smaller with advanced optimizations (about 12KB). One problem with that, however, is that it renames symbols quite rigidly, soxyz.MyEnumwould be renamed and when the lazy loader tries to find it, it won't be there any more.There are a couple of possible solutions I can see for this. We could either define the types as callbacks, e.g.
or we can define them with array notation:
to prevent them from being modified. Is there a reason why on a static build these are lazily evaluated at all?