Skip to content

Commit 8ef92a7

Browse files
authored
Merge branch 'main' into format-dirty
Signed-off-by: Nigro Simone <nigro.simone@gmail.com>
2 parents 7a2a31a + 144c271 commit 8ef92a7

File tree

11 files changed

+118
-147
lines changed

11 files changed

+118
-147
lines changed

.github/workflows/benchmark.yml

Lines changed: 0 additions & 85 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
push:
55
branches:
66
- main
7-
- master
87
- next
98
- 'v*'
109
paths-ignore:
@@ -15,8 +14,14 @@ on:
1514
- 'docs/**'
1615
- '*.md'
1716

17+
permissions:
18+
contents: read
19+
1820
jobs:
1921
test:
22+
permissions:
23+
contents: write
24+
pull-requests: write
2025
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5
2126
with:
2227
license-check: true

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
ignore-scripts=true
12
package-lock=false

LICENSE

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
The MIT License (MIT)
1+
MIT License
22

3-
Copyright (c) 2016-2018 Matteo Collina
3+
Copyright (c) 2016-present Matteo Collina
4+
Copyright (c) 2016-present The Fastify team
5+
6+
The Fastify team members are listed at https://github.com/fastify/fastify#team.
47

58
Permission is hereby granted, free of charge, to any person obtaining a copy
69
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# fast-json-stringify
22

3-
[![CI](https://github.com/fastify/fast-json-stringify/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/fast-json-stringify/actions/workflows/ci.yml)
3+
[![CI](https://github.com/fastify/fast-json-stringify/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/fast-json-stringify/actions/workflows/ci.yml)
44
[![NPM version](https://img.shields.io/npm/v/fast-json-stringify.svg?style=flat)](https://www.npmjs.com/package/fast-json-stringify)
55
[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)
66
[![NPM downloads](https://img.shields.io/npm/dm/fast-json-stringify.svg?style=flat)](https://www.npmjs.com/package/fast-json-stringify)
77

8-
98
__fast-json-stringify__ is significantly faster than `JSON.stringify()` for small payloads.
109
Its performance advantage shrinks as your payload grows.
1110
It pairs well with [__flatstr__](https://www.npmjs.com/package/flatstr), which triggers a V8 optimization that improves performance when eventually converting the string to a `Buffer`.
@@ -18,37 +17,43 @@ fast-json-stringify requires a [JSON Schema Draft 7](https://json-schema.org/spe
1817
##### Benchmarks
1918

2019
- Machine: `EX41S-SSD, Intel Core i7, 4Ghz, 64GB RAM, 4C/8T, SSD`.
21-
- Node.js `v18.12.1`
20+
- Node.js `v22.14.0`
2221

2322
```
24-
FJS creation x 4,129 ops/sec ±0.82% (92 runs sampled)
25-
CJS creation x 184,196 ops/sec ±0.12% (97 runs sampled)
26-
AJV Serialize creation x 61,130,591 ops/sec ±0.40% (92 runs sampled)
27-
JSON.stringify array x 5,057 ops/sec ±0.10% (100 runs sampled)
28-
fast-json-stringify array default x 6,243 ops/sec ±0.14% (98 runs sampled)
29-
fast-json-stringify array json-stringify x 6,261 ops/sec ±0.30% (99 runs sampled)
30-
compile-json-stringify array x 6,842 ops/sec ±0.18% (96 runs sampled)
31-
AJV Serialize array x 6,964 ops/sec ±0.11% (95 runs sampled)
32-
JSON.stringify large array x 248 ops/sec ±0.07% (90 runs sampled)
33-
fast-json-stringify large array default x 99.96 ops/sec ±0.22% (74 runs sampled)
34-
fast-json-stringify large array json-stringify x 248 ops/sec ±0.07% (90 runs sampled)
35-
compile-json-stringify large array x 317 ops/sec ±0.09% (89 runs sampled)
36-
AJV Serialize large array x 111 ops/sec ±0.07% (33 runs sampled)
37-
JSON.stringify long string x 16,002 ops/sec ±0.09% (98 runs sampled)
38-
fast-json-stringify long string x 15,979 ops/sec ±0.09% (96 runs sampled)
39-
compile-json-stringify long string x 15,952 ops/sec ±0.31% (97 runs sampled)
40-
AJV Serialize long string x 21,416 ops/sec ±0.08% (98 runs sampled)
41-
JSON.stringify short string x 12,944,272 ops/sec ±0.09% (96 runs sampled)
42-
fast-json-stringify short string x 30,585,790 ops/sec ±0.27% (97 runs sampled)
43-
compile-json-stringify short string x 30,656,406 ops/sec ±0.12% (96 runs sampled)
44-
AJV Serialize short string x 30,406,785 ops/sec ±0.37% (96 runs sampled)
45-
JSON.stringify obj x 3,153,043 ops/sec ±0.33% (99 runs sampled)
46-
fast-json-stringify obj x 6,866,434 ops/sec ±0.11% (100 runs sampled)
47-
compile-json-stringify obj x 15,886,723 ops/sec ±0.15% (98 runs sampled)
48-
AJV Serialize obj x 8,969,043 ops/sec ±0.36% (97 runs sampled)
49-
JSON stringify date x 1,126,547 ops/sec ±0.09% (97 runs sampled)
50-
fast-json-stringify date format x 1,836,188 ops/sec ±0.12% (99 runs sampled)
51-
compile-json-stringify date format x 1,125,735 ops/sec ±0.19% (98 runs sampled)
23+
FJS creation x 9,696 ops/sec ±0.77% (94 runs sampled)
24+
CJS creation x 197,267 ops/sec ±0.22% (95 runs sampled)
25+
AJV Serialize creation x 48,302,927 ops/sec ±2.09% (90 runs sampled)
26+
json-accelerator creation x 668,430 ops/sec ±0.43% (95 runs sampled)
27+
JSON.stringify array x 7,924 ops/sec ±0.11% (98 runs sampled)
28+
fast-json-stringify array default x 7,183 ops/sec ±0.09% (97 runs sampled)
29+
json-accelerator array x 5,762 ops/sec ±0.27% (99 runs sampled)
30+
fast-json-stringify array json-stringify x 7,171 ops/sec ±0.17% (97 runs sampled)
31+
compile-json-stringify array x 6,889 ops/sec ±0.41% (96 runs sampled)
32+
AJV Serialize array x 6,945 ops/sec ±0.17% (98 runs sampled)
33+
JSON.stringify large array x 331 ops/sec ±0.17% (93 runs sampled)
34+
fast-json-stringify large array default x 208 ops/sec ±0.21% (91 runs sampled)
35+
fast-json-stringify large array json-stringify x 330 ops/sec ±0.17% (93 runs sampled)
36+
compile-json-stringify large array x 318 ops/sec ±0.11% (90 runs sampled)
37+
AJV Serialize large array x 114 ops/sec ±0.27% (74 runs sampled)
38+
JSON.stringify long string x 13,452 ops/sec ±0.15% (99 runs sampled)
39+
fast-json-stringify long string x 13,454 ops/sec ±0.10% (99 runs sampled)
40+
json-accelerator long string x 13,439 ops/sec ±0.09% (98 runs sampled)
41+
compile-json-stringify long string x 13,380 ops/sec ±0.12% (100 runs sampled)
42+
AJV Serialize long string x 21,932 ops/sec ±0.06% (99 runs sampled)
43+
JSON.stringify short string x 12,114,052 ops/sec ±0.59% (97 runs sampled)
44+
fast-json-stringify short string x 29,408,175 ops/sec ±1.12% (91 runs sampled)
45+
json-accelerator short string x 29,431,694 ops/sec ±1.05% (93 runs sampled)
46+
compile-json-stringify short string x 24,740,338 ops/sec ±1.02% (91 runs sampled)
47+
AJV Serialize short string x 17,841,869 ops/sec ±0.90% (91 runs sampled)
48+
JSON.stringify obj x 4,577,494 ops/sec ±0.25% (94 runs sampled)
49+
fast-json-stringify obj x 7,291,157 ops/sec ±0.40% (97 runs sampled)
50+
json-accelerator obj x 6,473,194 ops/sec ±0.31% (99 runs sampled)
51+
compile-json-stringify obj x 14,724,935 ops/sec ±0.50% (96 runs sampled)
52+
AJV Serialize obj x 8,782,944 ops/sec ±0.45% (93 runs sampled)
53+
JSON stringify date x 803,522 ops/sec ±0.47% (98 runs sampled)
54+
fast-json-stringify date format x 1,117,776 ops/sec ±0.69% (95 runs sampled)
55+
json-accelerate date format x 1,122,419 ops/sec ±0.20% (97 runs sampled)
56+
compile-json-stringify date format x 803,214 ops/sec ±0.23% (97 runs sampled)
5257
```
5358

5459
#### Table of contents:

benchmark/bench-cmp-branch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const simpleGit = require('simple-git')
88
const git = simpleGit(process.cwd())
99

1010
const COMMAND = 'npm run bench'
11-
const DEFAULT_BRANCH = 'master'
11+
const DEFAULT_BRANCH = 'main'
1212
const PERCENT_THRESHOLD = 5
1313
const greyColor = '\x1b[30m'
1414
const redColor = '\x1b[31m'

benchmark/bench-cmp-lib.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ const ajvSerialize = ajv.compileSerializer(schemaAJVJTD)
118118
const ajvSerializeArray = ajv.compileSerializer(arraySchemaAJVJTD)
119119
const ajvSerializeString = ajv.compileSerializer({ type: 'string' })
120120

121+
const { createAccelerator } = require('json-accelerator')
122+
const accelStringify = createAccelerator(schema)
123+
const accelArray = createAccelerator(arraySchema)
124+
const accelDate = FJS(dateFormatSchema)
125+
const accelString = FJS({ type: 'string' })
126+
121127
const getRandomString = (length) => {
122128
if (!Number.isInteger(length)) {
123129
throw new Error('Expected integer length')
@@ -170,6 +176,9 @@ suite.add('CJS creation', function () {
170176
suite.add('AJV Serialize creation', function () {
171177
ajv.compileSerializer(schemaAJVJTD)
172178
})
179+
suite.add('json-accelerator creation', function () {
180+
createAccelerator(schema)
181+
})
173182

174183
suite.add('JSON.stringify array', function () {
175184
JSON.stringify(multiArray)
@@ -179,6 +188,10 @@ suite.add('fast-json-stringify array default', function () {
179188
stringifyArrayDefault(multiArray)
180189
})
181190

191+
suite.add('json-accelerator array', function () {
192+
accelArray(multiArray)
193+
})
194+
182195
suite.add('fast-json-stringify array json-stringify', function () {
183196
stringifyArrayJSONStringify(multiArray)
184197
})
@@ -219,6 +232,10 @@ suite.add('fast-json-stringify long string', function () {
219232
stringifyString(str)
220233
})
221234

235+
suite.add('json-accelerator long string', function () {
236+
stringifyString(str)
237+
})
238+
222239
suite.add('compile-json-stringify long string', function () {
223240
CJSStringifyString(str)
224241
})
@@ -235,6 +252,10 @@ suite.add('fast-json-stringify short string', function () {
235252
stringifyString('hello world')
236253
})
237254

255+
suite.add('json-accelerator short string', function () {
256+
accelString('hello world')
257+
})
258+
238259
suite.add('compile-json-stringify short string', function () {
239260
CJSStringifyString('hello world')
240261
})
@@ -251,6 +272,10 @@ suite.add('fast-json-stringify obj', function () {
251272
stringify(obj)
252273
})
253274

275+
suite.add('json-accelerator obj', function () {
276+
accelStringify(obj)
277+
})
278+
254279
suite.add('compile-json-stringify obj', function () {
255280
CJSStringify(obj)
256281
})
@@ -267,6 +292,10 @@ suite.add('fast-json-stringify date format', function () {
267292
stringifyDate(date)
268293
})
269294

295+
suite.add('json-accelerate date format', function () {
296+
accelDate(date)
297+
})
298+
270299
suite.add('compile-json-stringify date format', function () {
271300
CJSStringifyDate(date)
272301
})

0 commit comments

Comments
 (0)