Skip to content

Commit

Permalink
feat: remove fast-json-stringify
Browse files Browse the repository at this point in the history
With "fast-json-stringify":
simple message x 731,726 ops/sec ±1.00% (96 runs sampled)
message with printf x 604,838 ops/sec ±0.98% (95 runs sampled)
message with context x 660,218 ops/sec ±0.68% (97 runs sampled)
message with large context x 715,211 ops/sec ±1.52% (74 runs sampled)
message with large context x 724,470 ops/sec ±1.29% (77 runs sampled)

Without "fast-json-stringify":
simple message x 630,566 ops/sec ±0.59% (99 runs sampled)
message with printf x 551,880 ops/sec ±0.49% (100 runs sampled)
message with context x 577,205 ops/sec ±0.57% (99 runs sampled)
message with large context x 620,727 ops/sec ±1.03% (78 runs sampled)
message with large context x 622,001 ops/sec ±1.47% (76 runs sampled)

The difference is too minor at this point to make it worthwhile
  • Loading branch information
gajus committed Oct 30, 2023
1 parent 074e361 commit 34e4b9d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 41 deletions.
55 changes: 40 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
},
"browser": "./dist/browser.js",
"dependencies": {
"fast-json-stringify": "^5.8.0",
"fast-printf": "^1.6.9",
"safe-stable-stringify": "^2.4.3",
"semver-compare": "^1.0.0"
Expand Down
26 changes: 1 addition & 25 deletions src/Roarr.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,16 @@
import { createLogger } from './factories/createLogger';
import { createRoarrInitialGlobalState } from './factories/createRoarrInitialGlobalState';
import { type MessageSerializer, type RoarrGlobalState } from './types';
import fastJson from 'fast-json-stringify';
import safeStringify from 'safe-stable-stringify';

const fastStringify = fastJson({
properties: {
message: {
type: 'string',
},
sequence: {
type: 'string',
},
time: {
type: 'integer',
},
version: {
type: 'string',
},
},
type: 'object',
});

const ROARR = createRoarrInitialGlobalState(
(globalThis.ROARR as RoarrGlobalState) || {},
);

globalThis.ROARR = ROARR;

const serializeMessage: MessageSerializer = (message) => {
return (
'{"context":' +
safeStringify(message.context) +
',' +
fastStringify(message).slice(1)
);
return safeStringify(message);
};

const Roarr = createLogger((message) => {
Expand Down

0 comments on commit 34e4b9d

Please sign in to comment.