superjson
superjson copied to clipboard
Improve performance
Recent benchmarks against a similar library, devalue, read as follows:
superjson output: 179 bytes
devalue output: 116 bytes
() => superjson.stringify(obj)
1000000 iterations in 21005ms
() => devalue(obj)
1000000 iterations in 8168ms
() => superjson.parse(superjson_serialized)
1000000 iterations in 6487ms
() => eval(`(${devalue_serialized})`)
1000000 iterations in 2290ms
I’m not so concerned about the output size difference, which I think for now is negligible, but more about the speed. Obviously we’re making different design choices here which necessarily are probably slower, but I think it’d be good to see what improvements can be made in this area.
0.021005ms is pretty quick, though!
Thanks to Rich for setting up the comparison: https://github.com/Rich-Harris/superjson-and-devalue
Yeah, we'll definitely need to look into performance. I think there's a lot of low-hanging fruits to be reaped by changing stuff like [...path, head]
to path.push(head)
if that's possible.
We should tackle blitz-js/blitz#10 before this to have some objective measurement I guess :D
Yep! Was going to just comment on that but thought I’d set up a new issue.
One thing to keep in mind, is that on the server string<>object serialization & deserialization is currently handled by Next. So we won't use superjson.stringify
, but we will on the client.
That said, we could use superjson.stringify
on the server and bypass the Next res.json()
helper.
I’m not so concerned about the output size difference, which I think for now is negligible, but more about the speed.
In my opinion, we should focus the other way around. UX-wise, compute cycles are cheap but network usage is expensive.
So we already have a slow perf report from someone using Blitz, albeit to load 20k items in one request :)
https://github.com/blitz-js/legacy-framework/issues/778
Uh-oh ... I guess we‘ll need to look into adding a bigger benchmark case ^^
Is this still the case?