superjson icon indicating copy to clipboard operation
superjson copied to clipboard

Improve performance

Open merelinguist opened this issue 4 years ago • 8 comments

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

merelinguist avatar Jul 22 '20 18:07 merelinguist

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.

Skn0tt avatar Jul 22 '20 18:07 Skn0tt

We should tackle blitz-js/blitz#10 before this to have some objective measurement I guess :D

Skn0tt avatar Jul 22 '20 18:07 Skn0tt

Yep! Was going to just comment on that but thought I’d set up a new issue.

merelinguist avatar Jul 22 '20 18:07 merelinguist

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.

flybayer avatar Jul 23 '20 01:07 flybayer

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.

Skn0tt avatar Aug 03 '20 07:08 Skn0tt

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

flybayer avatar Aug 29 '20 20:08 flybayer

Uh-oh ... I guess we‘ll need to look into adding a bigger benchmark case ^^

Skn0tt avatar Aug 30 '20 08:08 Skn0tt

Is this still the case?

sannajammeh avatar Sep 01 '23 04:09 sannajammeh