Gathering detailed insights and metrics for fast-stable-stringify
Gathering detailed insights and metrics for fast-stable-stringify
Gathering detailed insights and metrics for fast-stable-stringify
Gathering detailed insights and metrics for fast-stable-stringify
fast-json-stable-stringify
deterministic `JSON.stringify()` - a faster version of substack's json-stable-strigify without jsonify
safe-stable-stringify
Deterministic and safely JSON.stringify to quickly serialize JavaScript objects
fast-safe-stringify
Safely and quickly serialize JavaScript objects
fastest-stable-stringify
Fastest stable deterministic JSON.stringify()
npm install fast-stable-stringify
Typescript
Module System
Node Version
NPM Version
JavaScript (99.39%)
Shell (0.61%)
Total Downloads
36,141,775
Last Day
66,031
Last Week
323,649
Last Month
1,392,841
Last Year
14,263,033
29 Stars
96 Commits
6 Forks
5 Watching
2 Branches
3 Contributors
Minified
Minified + Gzipped
Latest Version
1.0.0
Package Id
fast-stable-stringify@1.0.0
Size
27.41 kB
NPM Version
3.10.10
Node Version
6.11.2
Publised On
15 Sept 2017
Cumulative downloads
Total Downloads
Last day
-10.9%
66,031
Compared to previous day
Last week
-12.2%
323,649
Compared to previous week
Last month
8.7%
1,392,841
Compared to previous month
Last year
-1.3%
14,263,033
Compared to previous year
Notice: The License of this repository has been changed from GPL-3.0 to MIT as of 2017-08-25. All following commits will fall under the MIT license.
The test only succeeds when mine is faster than substack's in a particular browser.
The most popular repository providing this feature is substack's json-stable-stringify. The intent if this library is to provide a faster alternative for when performance is more important than features. It assumes you provide basic javascript values without circular references, and returns a non-indented string.
It currently offers a performance boost in popular browsers of about 40%. See the comparsion table below.
Usage:
1var stringify = require('fast-stable-stringify'); 2stringify({ d: 0, c: 1, a: 2, b: 3, e: 4 }); // '{"a":2,"b":3,"c":1,"d":0,"e":4}'
Just like substack's, it does:
JSON.stringify
Unlike substack's, it does:
Tested validity (answer equal to substack's) and benchmark (faster than substack's). A test passes only if it has the same output as substack's but is faster (as concluded by benchmark.js).
To (hopefully) prevent certain smart browsers from concluding the stringification is not necessary because it is never used anywhere, I summed up all the lengths of the resulting strings of each benchmark contestant and printed it along with the result data.
See caniuse browser usage for the 'most popular browsers'.
Suite | Browser | JSON.stringify@native | fast-stable-stringify@a9f81e8 | json-stable-stringify@1.0.1 | faster-stable-stringify@1.0.0 |
---|---|---|---|---|---|
libs | Chrome 60.0.3112 (Windows 7 0.0.0) | 414.45% (±2.67%) | *146.41% (±1.74%) | 100.00% (±1.11%) | 111.26% (±1.24%) |
libs | Chrome Mobile 55.0.2883 (Android 6.0.0) | 495.16% (±16.9%) | *162.18% (±3.59%) | 100.00% (±5.44%) | 129.66% (±3.20%) |
libs | Edge 14.14393.0 (Windows 10 0.0.0) | 487.88% (±11.9%) | *138.69% (±2.27%) | 100.00% (±1.51%) | 113.19% (±1.56%) |
libs | Firefox 54.0.0 (Windows 7 0.0.0) | 530.66% (±17.6%) | *169.34% (±2.38%) | 100.00% (±1.68%) | 152.30% (±2.48%) |
libs | IE 10.0.0 (Windows 7 0.0.0) | 427.80% (±10.9%) | *183.26% (±3.02%) | 100.00% (±2.42%) | ? |
libs | IE 11.0.0 (Windows 7 0.0.0) | 298.01% (±4.35%) | *136.25% (±1.89%) | 100.00% (±1.73%) | ? |
libs | IE 9.0.0 (Windows 7 0.0.0) | 316.18% (±4.01%) | *170.14% (±2.30%) | 100.00% (±1.52%) | ? |
libs | Mobile Safari 10.0.0 (iOS 10.3.0) | 554.98% (±23.7%) | *115.33% (±4.23%) | 100.00% (±3.11%) | *118.66% (±2.96%) |
libs | Safari 10.0.1 (Mac OS X 10.12.1) | 722.94% (±24.8%) | *119.49% (±3.62%) | 100.00% (±2.12%) | 106.06% (±3.12%) |
Click the build status badge to view the original output.
Disclaimer: the more I test the more I realize how many factors actually affect the outcome. Not only the browser and browser version, but particularly the json content and a random factor in every test run. Outcomes may sometimes vary more than 10% between tests, despite my attempt to reduce this by increasing the sample size to 2.5 times. Nevertheless, the overall picture typically still holds.
JSON.stringify
has been added for reference. In general, aside from the cases where you need the guarantee of a stable result, I would recommend against using this library, or any stable stringification library for that matter.
faster-stable-stringify
has been added for comparison. It seems it does not work in IE 9 to 11 without a polyfill solution for WeakMap. It is displayed as somewhat slower, but as I decided on the JSON input to test and develop against, this result may be somewhat biased. In some test runs, faster-stable-stringify
will be faster in a browser. In fact, it is consistently somewhat faster in the Mobile Safari 10.
The original implementation was with regexp. A pull request showed a literal string approach that was faster in some browsers. Other libraries would just use JSON.stringify. After a speed comparison between all three methods, it became clear that native JSON.stringify is generally much faster in string escaping than both these methods, even in the IE legacy browsers. The browsers that do not have JSON.stringify
are not offered for test automation, and when looking at the usage percentage of such browsers I no longer see a reason to not use JSON.stringify
.
Therefore, the exposed regexp and string are removed from the API. If you still need this functionality, I simply encourage you to use JSON.stringify
.
It runs karma-benchmark tests now. For testing in node, do:
npm test
This requires saucelabs credentials in your env. That, or edit the karma.conf.js to your liking.
Running this test will cause files in ./results/libs/
to update. Run npm run table
to get a pretty md table of the results.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 1/29 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More