msgpackr 1.11.9 → 1.11.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -2
- package/benchmark.md +26 -16
- package/dist/index-no-eval.cjs +10 -10
- package/dist/index-no-eval.cjs.map +1 -1
- package/dist/index-no-eval.min.js +1 -1
- package/dist/index-no-eval.min.js.map +1 -1
- package/dist/index.js +10 -10
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/node.cjs +10 -10
- package/dist/node.cjs.map +1 -1
- package/dist/test.js +10 -10
- package/dist/test.js.map +1 -1
- package/dist/unpack-no-eval.cjs +10 -10
- package/dist/unpack-no-eval.cjs.map +1 -1
- package/package.json +1 -1
- package/unpack.js +10 -10
package/README.md
CHANGED
|
@@ -7,8 +7,6 @@
|
|
|
7
7
|
[](README.md)
|
|
8
8
|
[](LICENSE)
|
|
9
9
|
|
|
10
|
-
<img align="right" src="./assets/performance.png" width="380"/>
|
|
11
|
-
|
|
12
10
|
The msgpackr package is an extremely fast MessagePack NodeJS/JavaScript implementation. Currently, it is significantly faster than any other known implementations, faster than Avro (for JS), and generally faster than native V8 JSON.stringify/parse, on NodeJS. It also includes an optional record extension (the `r` in msgpackr), for defining record structures that makes MessagePack even faster and more compact, often over twice as fast as even native JSON functions, several times faster than other JS implementations, and 15-50% more compact. See the performance section for more details. Structured cloning (with support for cyclical references) is also supported through optional extensions.
|
|
13
11
|
|
|
14
12
|
## Basic Usage
|
package/benchmark.md
CHANGED
|
@@ -1,24 +1,34 @@
|
|
|
1
1
|
Here are more comprehensive benchmarks. This is comparison with the next fastest JS projects using the benchmark tool from `msgpack-lite` (and data is from some clinical research data we use that has a good mix of different value types and structures). It also includes comparison to V8 native JSON functionality, and JavaScript Avro (`avsc`, a very optimized Avro implementation):
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
require("msgpackr").
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
require("
|
|
16
|
-
require("
|
|
17
|
-
require("
|
|
18
|
-
require("
|
|
3
|
+
---------------------------------------------------------- | ------: | ----: | -----: | -----:
|
|
4
|
+
msgpackr w/ shared structures: packr.pack(obj); | 254700 | 5001 | 50929
|
|
5
|
+
msgpackr w/ shared structures: packr.unpack(buf); | 711700 | 5000 | 142340
|
|
6
|
+
require("msgpackr").pack(obj); | 234000 | 5000 | 46800
|
|
7
|
+
require("msgpackr").unpack(buf); | 186500 | 5000 | 37300
|
|
8
|
+
buf = Buffer(JSON.stringify(obj)); | 297900 | 5000 | 59580
|
|
9
|
+
obj = JSON.parse(buf); | 216600 | 5001 | 43311
|
|
10
|
+
buf = require("msgpack-lite").encode(obj); | 114000 | 5001 | 22795
|
|
11
|
+
obj = require("msgpack-lite").decode(buf); | 40700 | 5006 | 8130
|
|
12
|
+
buf = require("@msgpack/msgpack").encode(obj); | 166100 | 5000 | 33220
|
|
13
|
+
obj = require("@msgpack/msgpack").decode(buf); | 136500 | 5002 | 27289
|
|
14
|
+
buf = require("msgpack-js-v5").encode(obj); | 41600 | 5000 | 8320
|
|
15
|
+
obj = require("msgpack-js-v5").decode(buf); | 70200 | 5004 | 14028
|
|
16
|
+
buf = require("msgpack-js").encode(obj); | 40400 | 5012 | 8060
|
|
17
|
+
obj = require("msgpack-js").decode(buf); | 67100 | 5002 | 13414
|
|
18
|
+
buf = require("msgpack5")().encode(obj); | 15800 | 5024 | 3144
|
|
19
|
+
obj = require("msgpack5")().decode(buf); | 30600 | 5004 | 6115
|
|
20
|
+
buf = require("notepack").encode(obj); | 125100 | 5002 | 25009
|
|
21
|
+
obj = require("notepack").decode(buf); | 98600 | 5004 | 19704
|
|
22
|
+
require("what-the-pack")... encoder.encode(obj); | 150300 | 5001 | 30053
|
|
23
|
+
require("what-the-pack")... encoder.decode(buf); | 100100 | 5000 | 20020
|
|
24
|
+
obj = require("msgpack-unpack").decode(buf); | 14900 | 5031 | 2961
|
|
25
|
+
require("avsc")...make schema/type...type.toBuffer(obj); | 266600 | 5000 | 53320
|
|
26
|
+
require("avsc")...make schema/type...type.fromBuffer(obj); | 370200 | 5000 | 74040
|
|
19
27
|
|
|
20
28
|
(`avsc` is schema-based and more comparable in style to msgpackr with shared structures).
|
|
21
29
|
|
|
30
|
+
(note that benchmarks below are several years old)
|
|
31
|
+
|
|
22
32
|
Here is a benchmark of streaming data (again borrowed from `msgpack-lite`'s benchmarking), where msgpackr is able to take advantage of the structured record extension and really pull away from other tools:
|
|
23
33
|
|
|
24
34
|
operation (1000000 x 2) | op | ms | op/s
|
package/dist/index-no-eval.cjs
CHANGED
|
@@ -31,13 +31,6 @@
|
|
|
31
31
|
var inlineObjectReadThreshold = 2;
|
|
32
32
|
var readStruct;
|
|
33
33
|
var BlockedFunction; // we use search and replace to change the next call to BlockedFunction to avoid CSP issues for
|
|
34
|
-
// no-eval build
|
|
35
|
-
try {
|
|
36
|
-
new BlockedFunction ('');
|
|
37
|
-
} catch(error) {
|
|
38
|
-
// if eval variants are not supported, do not create inline object readers ever
|
|
39
|
-
inlineObjectReadThreshold = Infinity;
|
|
40
|
-
}
|
|
41
34
|
|
|
42
35
|
class Unpackr {
|
|
43
36
|
constructor(options) {
|
|
@@ -503,11 +496,18 @@
|
|
|
503
496
|
function readObject() {
|
|
504
497
|
// This initial function is quick to instantiate, but runs slower. After several iterations pay the cost to build the faster function
|
|
505
498
|
if (readObject.count++ > inlineObjectReadThreshold) {
|
|
506
|
-
let
|
|
507
|
-
|
|
499
|
+
let optimizedReadObject;
|
|
500
|
+
try {
|
|
501
|
+
optimizedReadObject = structure.read = (new BlockedFunction ('r', 'return function(){return ' + (currentUnpackr.freezeData ? 'Object.freeze' : '') +
|
|
502
|
+
'({' + structure.map(key => key === '__proto__' ? '__proto_:r()' : validName.test(key) ? key + ':r()' : ('[' + JSON.stringify(key) + ']:r()')).join(',') + '})}'))(read);
|
|
503
|
+
} catch(error) {
|
|
504
|
+
// in CF workers, the new BlockedFunction call could begin to fail at any point in time
|
|
505
|
+
inlineObjectReadThreshold = Infinity; // disable going forward
|
|
506
|
+
return readObject(); // recursively try again
|
|
507
|
+
}
|
|
508
508
|
if (structure.highByte === 0)
|
|
509
509
|
structure.read = createSecondByteReader(firstId, structure.read);
|
|
510
|
-
return
|
|
510
|
+
return optimizedReadObject() // second byte is already read, if there is one so immediately read object
|
|
511
511
|
}
|
|
512
512
|
let object = {};
|
|
513
513
|
for (let i = 0, l = structure.length; i < l; i++) {
|