You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Is there a reason why on a static build these are lazily evaluated at all?
The $root object is assembled linearly in static code, hence a type reference from message 1, which is declared first, to message 2 might not yet be there (undefined or a TypeError if even the parent namespace isn't there yet).
We could either define the types as callbacks
I like this approach.
Edit: Alternatively, access to types[N] in generated functions could even be replaced with direct references.
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.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.
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?
The text was updated successfully, but these errors were encountered: