Skip to content

Commit

Permalink
Stripped out fallback encoder/decoder/verifier completely (even IE8 s…
Browse files Browse the repository at this point in the history
…upports codegen), significantly reduces bundle size, can use static codegen elsewhere
  • Loading branch information
dcodeIO committed Dec 18, 2016
1 parent c234de7 commit bfac0ea
Show file tree
Hide file tree
Showing 22 changed files with 185 additions and 884 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ While .proto and JSON files require the full library (about 18kb gzipped), prett

Static code, on the other hand, requires just the minimal runtime (about 5.5kb gzipped), but generates additional, albeit editable, source code without any reflection features.

Where `new Function(...)` is supported (it usually is), there is no difference performance-wise as the code generated statically is pretty much the same as generated at runtime.
There is no difference performance-wise as the code generated statically is pretty much the same as generated at runtime.

Building
--------
Expand Down Expand Up @@ -493,8 +493,6 @@ Note that JSON is a native binding nowadays and as such is about as fast as it p
* For entirely bogus values encoders intentionally rely on runtime errors to be thrown somewhere down the road.
* Quite a bit of V8-specific profiling is accountable for everything else.

Note that code generation requires `new Function(...)` (basically `eval`) support and that an equivalent but slower fallback will be used where unsupported.

You can also run [the benchmark](https://github.com/dcodeIO/protobuf.js/blob/master/bench/index.js) ...

```
Expand Down
6 changes: 3 additions & 3 deletions cli/targets/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ function buildType(ref, type) {
"@param {Writer} [writer] Writer to encode to",
"@returns {Writer} Writer"
]);
buildFunction(type, "encode", protobuf.encode.generate(type), {
buildFunction(type, "encode", protobuf.encoder(type), {
Writer : "$protobuf.Writer",
util : "$protobuf.util"
});
Expand Down Expand Up @@ -318,7 +318,7 @@ function buildType(ref, type) {
"@param {number} [length] Message length if known beforehand",
"@returns {" + fullName + "} " + type.name
]);
buildFunction(type, "decode", protobuf.decode.generate(type), {
buildFunction(type, "decode", protobuf.decoder(type), {
Reader : "$protobuf.Reader",
util : "$protobuf.util"
});
Expand Down Expand Up @@ -351,7 +351,7 @@ function buildType(ref, type) {
"@param {" + fullName + "|Object} message " + type.name + " or plain object to verify",
"@returns {?string} `null` if valid, otherwise the reason why it is not"
]);
buildFunction(type, "verify", protobuf.verify.generate(type), {
buildFunction(type, "verify", protobuf.verifier(type), {
util : "$protobuf.util"
});

Expand Down
Loading

0 comments on commit bfac0ea

Please sign in to comment.