Follow

I don’t know who needs to hear this but, having been looking at performance characteristics of JSON in Node.js today:

- JSON.stringify (synchronous) is blisteringly fast on regular JavaScript objects/arrays, etc.
- JSON.stringify is an order of magnitude slower when used with Proxy
- The fastest yielding module I could find (yieldableJSON) is an order of magnitude slower than JSON.stringify.

Also, { performance } = require('perf_hooks'); performance.now() is your friend ;)

· · Web · 3 · 2 · 3

@aral accepting the overall performance hit might be worth it for being non blocking.

on the other hand, workers might be a better way to get there.

@zensaiyuki Yeah, if you’re working with huge data, definitely. But with 1,000,000 records of my test database I’m closing ~600ms on writes (~150MB table) so that’s acceptable for me (given that I don’t expect to reach 100,000 records for my use case in actual use and writes are ~50ms at that stage). Basically, if we ever reach 100K for this use case, it would mean we’re making ~€200K/month and thus we should be trying harder to devolve accounts AWAY from us, not to us so as not to centralise :)

@aral Have you already looked at fast-json-stringify?
github.com/fastify/fast-json-s

I haven't used it myself, but it looks really promising, especially for stringifying objects (according to benchmarks).

Also it seems really well maintained.👍

@janriemer I had not, thanks for the heads up, Jan. (Although I probably won’t be using it for this as it requires a schema but interesting nevertheless) :)

@aral Oh, I haven't seen that it requires a schema, sorry. But it makes sense. Thanks for pointing it out. 😉

Sign in to participate in the conversation
Aral’s Mastodon

The social network of the future: No ads, no corporate surveillance, ethical design, and decentralization! Own your data with Mastodon!