
Security News
GitHub Actions Pricing Whiplash: Self-Hosted Actions Billing Change Postponed
GitHub postponed a new billing model for self-hosted Actions after developer pushback, but moved forward with hosted runner price cuts on January 1.
msgpack-nodejs
Advanced tools
Really fast MessagePack encoder/decoder implemented in Node.js/Typescript
Yet another javascript/nodejs implementation of MsgPack Spec.
The purpose behind is learning by doing, which focuses on modern tools/techniques of nodejs/typescript ecosystem.
npm i msgpack-nodejs
npm test
Please check example.md
any => Uint8ArrayUint8Array => Exclude<any, Map>Exclude<any, null> => BufferBuffer => Exclude<any, null> 1You can apply options like this
| Key | type | default | Description |
|---|---|---|---|
| encoder.mapKeyCache.enabled | boolean | true | Cache map-key or not |
| encoder.mapKeyCache.size | number | 30 | How big is the mapKeyCache |
| encoder.stringCache.enabled | boolean | true | Cache any string except map-key or not |
| encoder.stringCache.size | number | 100 | How big is the stringCache |
| encoder.byteArray.base | number | 1024 | How many bytes will be allocated for every execution. Setting this would increase performance when handling many big JSON data |
| decoder.shortStringCache.enabled | boolean | true | Use prefix-trie or not |
| decoder.shortStringCache.lessThan | number | 10 | Only cache if string is shorter than this value |
| decoder.jsUtf8Decode.enabled | boolean | true | Use JS utf8-decode or not |
| decoder.jsUtf8Decode.lessThan | number | 200 | Only use JS utf8-decode if string is shorter than this value |
| Env | Executable? |
|---|---|
| Node.js 18 | ✅ |
| Node.js 16 | ✅ |
| Node.js 14 | ✅ |
| Node.js 12 | ❌ |
By utlizing the great benchmark tool by msgpack-lite, I thought the performance of this project would not be disappointing.
Runs on node.js 16 & laptop with R5-5625U.
| operation | op | ms | op/s |
|---|---|---|---|
| buf = Buffer(JSON.stringify(obj)); | 1021200 | 5000 | 204240 |
| obj = JSON.parse(buf); | 1279500 | 5000 | 255900 |
| buf = require("msgpack-lite").encode(obj); | 685800 | 5000 | 137160 |
| obj = require("msgpack-lite").decode(buf); | 389800 | 5001 | 77944 |
| buf = Buffer(require("msgpack.codec").msgpack.pack(obj)); | 713600 | 5000 | 142720 |
| obj = require("msgpack.codec").msgpack.unpack(buf); | 401300 | 5001 | 80243 |
| buf = require("msgpack-js-v5").encode(obj); | 284400 | 5000 | 56880 |
| obj = require("msgpack-js-v5").decode(buf); | 544600 | 5000 | 108920 |
| buf = require("msgpack-js").encode(obj); | 277100 | 5001 | 55408 |
| obj = require("msgpack-js").decode(buf); | 559800 | 5000 | 111960 |
| buf = require("msgpack5")().encode(obj); | 147700 | 5001 | 29534 |
| obj = require("msgpack5")().decode(buf); | 239500 | 5000 | 47900 |
| buf = require("notepack").encode(obj); | 1041500 | 5000 | 208300 |
| obj = require("notepack").decode(buf); | 671300 | 5000 | 134260 |
| obj = require("msgpack-unpack").decode(buf); | 163400 | 5001 | 32673 |
| buf = require("msgpack-nodejs").encode(obj); (Run in sequence) | 1148900 | 5000 | 229780 |
| obj = require("msgpack-nodejs").decode(buf); (Run in sequence) | 777500 | 5000 | 155500 |
| buf = require("msgpack-nodejs").encode(obj); (Run exclusively) | 1321900 | 5000 | 264380 |
| obj = require("msgpack-nodejs").decode(buf); (Run exclusively) | 805400 | 5000 | 161080 |
Encoder uses a recursive function match() to match JSON structure (primitive value, object, array or nested), and pushes anything encoded into ByteArray that responsible for allocating buffer. Encoded string will be written in StringBuffer first and cached in LruCache.
Decoder uses parseBuffer() to read every value out, and push them into StructBuilder to rebuild whole JSON object. For string less than 200 bytes, use pure JS utf8Decode(), then cache in prefix trie.
DataView calls as much as possible.subarray() for writing and caching. 4TextDecoder(), decode UTF-8 bytes with pure JS when less than 200 bytes. 3builder.insertValue() directly. 5After attaching another stream that does not expect a object as its input, you may encounter error ↩
Thanks to kriszyp/msgpackr for inspiration of better buffer allocation strategy. ↩
Thanks to AppSpector, this article gives very practical advices including pre-allocated array and manual decoding under 200 characters. ↩ ↩2 ↩3
Thanks to msgpack/msgpack-javascript for technique including UTF-8 bytes calculation and usage of encodeInto(), which led me to the ultra optimization strategy. ↩
使用 ESLint, Prettier, Husky, Lint-staged 以及 Commitizen 提升專案品質及一致性 ↩
FAQs
Really fast MessagePack encoder/decoder implemented in Node.js/Typescript
The npm package msgpack-nodejs receives a total of 1 weekly downloads. As such, msgpack-nodejs popularity was classified as not popular.
We found that msgpack-nodejs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
GitHub postponed a new billing model for self-hosted Actions after developer pushback, but moved forward with hosted runner price cuts on January 1.

Research
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.