quick script to compare the performance/output of superjson and devalue, following this Twitter thread.
git clone git@github.com:Rich-Harris/superjson-and-devalue
cd superjson-and-devalue
npm i
node index.js
The sample object is small and simple — different objects may have different outcomes.
Note: I couldn't get things like Sets or repeated references to work with superjson (it complained about circular references).
To see how much superjson.deserialize
adds to the client bundle, run this:
npm run build
cat bundle-size/output-superjson.js | wc -c
(With Terser installed globally, you can do cat bundle-size/output-superjson.js | terser -cm | wc -c
to check minified size, or chuck a | gzip -9
in there to see zipped size.)
In node 16.15.1 on an M1 Max, devalue@2.0.1
handily beats superjson@1.9.1
on all tests:
superjson output: 183 bytes
devalue output: 116 bytes
() => superjson.stringify(obj)
1000000 iterations in 8543ms
() => devalue(obj)
1000000 iterations in 3190ms
() => superjson.parse(superjson_serialized)
1000000 iterations in 3343ms
() => eval(`(${devalue_serialized})`)
1000000 iterations in 261ms
superjson.deserialize
adds 12.3kb to your client bundle size. (devalue
adds 0kb, because there's no runtime.)