-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix!: increase encoding/decoding performance (#58)
Switches the internal serialization/deserialization code to use the Reader/Writer from protobufjs as it's very fast and also the least interesting thing about this module. ```console % node packages/protons-benchmark/dist/src/encode.js pbjs x 1,067,457 ops/sec ±1.74% (83 runs sampled) protons x 1,165,064 ops/sec ±2.78% (90 runs sampled) protobufjs x 1,317,685 ops/sec ±2.73% (89 runs sampled) Fastest is protobufjs ``` ```console % node packages/protons-benchmark/dist/src/decode.js pbjs x 1,997,186 ops/sec ±0.87% (86 runs sampled) protons x 1,490,204 ops/sec ±2.40% (90 runs sampled) protobufjs x 1,809,549 ops/sec ±0.58% (88 runs sampled) Fastest is pbjs ``` ```console % node packages/protons-benchmark/dist/src/index.js pbjs x 11,307 ops/sec ±6.04% (86 runs sampled) protons x 11,376 ops/sec ±2.33% (80 runs sampled) protobufjs x 12,086 ops/sec ±1.84% (89 runs sampled) Fastest is protobufjs,pbjs ``` ```console % node packages/protons-benchmark/dist/src/rpc.js protons x 3,308,190 ops/sec ±0.57% (92 runs sampled) protobufjs x 3,135,946 ops/sec ±2.14% (91 runs sampled) Fastest is protons ``` BREAKING CHANGE: the exported types of `protons-runtime` have changed and protobuf encoders/decoders will need to be regenerated
- Loading branch information
1 parent
dab81db
commit 9987b97
Showing
48 changed files
with
7,429 additions
and
832 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ node_modules | |
package-lock.json | ||
yarn.lock | ||
.clinic | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
syntax = "proto3"; | ||
|
||
message Foo { | ||
optional uint32 baz = 1; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* eslint-disable no-console */ | ||
|
||
/* | ||
$ node dist/src/index.js | ||
$ npx playwright-test dist/src/index.js --runner benchmark | ||
*/ | ||
|
||
import Benchmark from 'benchmark' | ||
import { Test as ProtonsTest } from './protons/bench.js' | ||
import { decodeTest as pbjsDecodeTest } from './pbjs/bench.js' | ||
import { Test as ProtobufjsTest } from './protobufjs/bench.js' | ||
|
||
const message = { | ||
meh: { | ||
lol: 'sdkljfoee', | ||
b: { | ||
tmp: { | ||
baz: 2309292 | ||
} | ||
} | ||
}, | ||
hello: 3493822, | ||
foo: 'derp derp derp', | ||
payload: Uint8Array.from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) | ||
} | ||
|
||
const buf = ProtonsTest.encode(message).subarray() | ||
|
||
new Benchmark.Suite() | ||
.add('pbjs', () => { | ||
pbjsDecodeTest(buf) | ||
}) | ||
.add('protons', () => { | ||
ProtonsTest.decode(buf) | ||
}) | ||
.add('protobufjs', () => { | ||
ProtobufjsTest.decode(buf) | ||
}) | ||
.on('error', (err: Error) => { | ||
console.error(err) | ||
}) | ||
.on('cycle', (event: any) => { | ||
console.info(String(event.target)) | ||
}) | ||
.on('complete', function () { | ||
// @ts-expect-error types are wrong | ||
console.info(`Fastest is ${this.filter('fastest').map('name')}`) // eslint-disable-line @typescript-eslint/restrict-template-expressions | ||
}) | ||
// run async | ||
.run({ async: true }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* eslint-disable no-console */ | ||
|
||
/* | ||
$ node dist/src/index.js | ||
$ npx playwright-test dist/src/index.js --runner benchmark | ||
*/ | ||
|
||
import Benchmark from 'benchmark' | ||
import { Test as ProtonsTest } from './protons/bench.js' | ||
import { encodeTest as pbjsEncodeTest } from './pbjs/bench.js' | ||
import { Test as ProtobufjsTest } from './protobufjs/bench.js' | ||
|
||
const message = { | ||
meh: { | ||
lol: 'sdkljfoee', | ||
b: { | ||
tmp: { | ||
baz: 2309292 | ||
} | ||
} | ||
}, | ||
hello: 3493822, | ||
foo: 'derp derp derp', | ||
payload: Uint8Array.from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) | ||
} | ||
|
||
new Benchmark.Suite() | ||
.add('pbjs', () => { | ||
pbjsEncodeTest(message) | ||
}) | ||
.add('protons', () => { | ||
ProtonsTest.encode(message) | ||
}) | ||
.add('protobufjs', () => { | ||
ProtobufjsTest.encode(message).finish() | ||
}) | ||
.on('error', (err: Error) => { | ||
console.error(err) | ||
}) | ||
.on('cycle', (event: any) => { | ||
console.info(String(event.target)) | ||
}) | ||
.on('complete', function () { | ||
// @ts-expect-error types are wrong | ||
console.info(`Fastest is ${this.filter('fastest').map('name')}`) // eslint-disable-line @typescript-eslint/restrict-template-expressions | ||
}) | ||
// run async | ||
.run({ async: true }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.