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
The `protobuf` namespace will be available globally.
81
-
82
80
**NOTE:** Remember to replace the version tag with the exact [release](https://github.com/dcodeIO/protobuf.js/releases) your project depends upon.
83
81
82
+
Or [download](https://github.com/dcodeIO/protobuf.js/tree/master/dist) the library.
83
+
84
+
The `protobuf` namespace will always be available globally but also supports AMD.
While .proto and JSON files require the full library (about 20kb gzipped), pretty much all code but the relatively short descriptors is shared.
342
-
343
-
Static code, on the other hand, requires just the runtime library (about 5kb gzipped), but generates relatively large code bases without any reflection features.
344
-
345
-
When `new Function` is supported (and it usually is), there is no difference performance-wise as the code generated statically is the same generated at runtime.
346
-
347
341
### Generating TypeScript definitions from static modules
348
342
349
343
Likewise, the `pbts` command line utility can be used to generate TypeScript definitions from `pbjs`-generated static modules.
While .proto and JSON files require the full library (about 18kb gzipped), pretty much all code but the relatively short descriptors is shared.
358
+
359
+
Static code, on the other hand, requires just the minimal runtime (about 5.5kb gzipped), but generates relatively large code bases without any reflection features.
360
+
361
+
When `new Function` is supported (and it usually is), there is no difference performance-wise as the code generated statically is the same generated at runtime.
362
+
361
363
Building
362
364
--------
363
365
@@ -404,37 +406,37 @@ The package includes a benchmark that tries to compare performance to native JSO
404
406
```
405
407
benchmarking encoding performance ...
406
408
407
-
Type.encode to buffer x 479,876 ops/sec ±0.64% (92 runs sampled)
408
-
JSON.stringify to string x 311,489 ops/sec ±0.84% (87 runs sampled)
409
-
JSON.stringify to buffer x 175,079 ops/sec ±1.48% (82 runs sampled)
409
+
Type.encode to buffer x 481,172 ops/sec ±0.48% (92 runs sampled)
410
+
JSON.stringify to string x 307,509 ops/sec ±1.04% (92 runs sampled)
411
+
JSON.stringify to buffer x 164,463 ops/sec ±1.37% (89 runs sampled)
410
412
411
413
Type.encode to buffer was fastest
412
-
JSON.stringify to string was 35.2% slower
413
-
JSON.stringify to buffer was 63.8% slower
414
+
JSON.stringify to string was 36.4% slower
415
+
JSON.stringify to buffer was 66.1% slower
414
416
415
417
benchmarking decoding performance ...
416
418
417
-
Type.decode from buffer x 1,267,612 ops/sec ±1.18% (90 runs sampled)
418
-
JSON.parse from string x 291,707 ops/sec ±1.12% (92 runs sampled)
419
-
JSON.parse from buffer x 262,640 ops/sec ±0.77% (89 runs sampled)
419
+
Type.decode from buffer x 1,319,810 ops/sec ±0.71% (92 runs sampled)
420
+
JSON.parse from string x 298,578 ops/sec ±0.98% (90 runs sampled)
421
+
JSON.parse from buffer x 267,471 ops/sec ±0.81% (89 runs sampled)
420
422
421
423
Type.decode from buffer was fastest
422
-
JSON.parse from string was 77.0% slower
423
-
JSON.parse from buffer was 79.2% slower
424
+
JSON.parse from string was 77.4% slower
425
+
JSON.parse from buffer was 79.8% slower
424
426
425
427
benchmarking combined performance ...
426
428
427
-
Type to/from buffer x 248,897 ops/sec ±0.89% (90 runs sampled)
428
-
JSON to/from string x 126,848 ops/sec ±0.75% (92 runs sampled)
429
-
JSON to/from buffer x 89,854 ops/sec ±0.79% (93 runs sampled)
429
+
Type to/from buffer x 262,728 ops/sec ±0.92% (92 runs sampled)
430
+
JSON to/from string x 129,405 ops/sec ±0.78% (94 runs sampled)
431
+
JSON to/from buffer x 89,523 ops/sec ±0.71% (89 runs sampled)
430
432
431
433
Type to/from buffer was fastest
432
-
JSON to/from string was 49.0% slower
433
-
JSON to/from buffer was 63.9% slower
434
+
JSON to/from string was 50.7% slower
435
+
JSON to/from buffer was 65.9% slower
434
436
435
437
benchmarking verifying performance ...
436
438
437
-
Type.verify x 5,941,014 ops/sec ±0.96% (90 runs sampled)
439
+
Type.verify x 5,833,382 ops/sec ±0.98% (85 runs sampled)
Copy file name to clipboardExpand all lines: dist/README.md
+2
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
1
This folder contains prebuilt browser versions of [protobuf.js](https://github.com/dcodeIO/protobuf.js). When sending pull requests, it is not required to update these.
2
2
3
+
Alternatively, you can also use [the minimal runtime](./runtime) when working with statically generated code from `pbjs`*only*.
4
+
3
5
Prebuilt files are in source control to enable pain-free frontend respectively CDN usage:
Copy file name to clipboardExpand all lines: dist/runtime/README.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
-
This folder contains prebuilt browser versions of [protobuf.js](https://github.com/dcodeIO/protobuf.js)'s runtime for statically generated code. When sending pull requests, it is not required to update these.
1
+
This folder contains prebuilt browser versions of [protobuf.js](https://github.com/dcodeIO/protobuf.js)'s minimal runtime for statically generated code. When sending pull requests, it is not required to update these.
2
2
3
-
**NOTE:** The static code runtime includes just the bare minimum required to work with statically generated modules - and *nothing else*. Where applicable, it can be used as a drop-in replacement for the full library as it has the same general structure.
3
+
**NOTE:** The minimal runtime includes just the bare minimum required to work with statically generated code - and *nothing else*. Where applicable, it can be used as a drop-in replacement for the full library as it has the same general structure.
4
4
5
5
Prebuilt files are in source control to enable pain-free frontend respectively CDN usage:
0 commit comments