frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

How we made JSON.stringify more than twice as fast

https://v8.dev/blog/json-stringify
131•emschwartz•9h ago

Comments

hinkley•6h ago
JSON encoding is a huge impediment to interprocess communication in NodeJS.

Sooner or later is seems like everyone gets the idea of reducing event loop stalls in their NodeJS code by trying to offload it to another thread, only to discover they’ve tripled the CPU load in the main thread.

I’ve seen people stringify arrays one entry at a time. Sounds like maybe they are doing that internally now.

If anything I would encourage the V8 team to go farther with this. Can you avoid bailing out for subsets of data? What about the CString issue? Does this bring faststr back from the dead?

jcdavis•3h ago
Based off of my first ever forays into node performance analysis last year, JSON.stringify was one of the biggest impediments to just about everything around performant node services. The fact that everyone uses stringify to for dict keys, the fact that apollo/express just serializes the entire response into a string instead of incrementally streaming it back (I think there are some possible workarounds for this, but they seemed very hacky)

As someone who has come from a JVM/go background, I was kinda shocked how amateur hour it felt tbh.

MehdiHK•2h ago
> JSON.stringify was one of the biggest impediments to just about everything around performant node services

That's what I experienced too. But I think the deeper problem is Node's cooperative multitasking model. A preemptive multitasking (like Go) wouldn't block the whole event-loop (other concurrent tasks) during serializing a large response (often the case with GraphQL, but possible with any other API too). Yeah, it does kinda feel like amateur hour.

hinkley•2h ago
> Based off of my first ever forays into node performance analysis last year, JSON.stringify was one of the biggest impediments to just about everything around performant node services

Just so. It is, or at least can be, the plurality of the sequential part of any Amdahl's Law calculation for Nodejs.

I'm curious if any of the 'side effect free' commentary in this post is about moving parts of the JSON calculation off of the event loop. That would certainly be very interesting if true.

However for concurrency reasons I suspect it could never be fully off. The best you could likely do is have multiple threads converting the object while the event loop remains blocked. Not entirely unlike concurrent marking in the JVM.

dmit•1h ago
Node is the biggest impediment to performant Node services. The entire value proposition is "What if you could hire people who write code in the most popular programming language in the world?" Well, guess what
brundolf•2h ago
Yeah. I think I've only ever found one situation where offloading work to a worker saved more time than was lost through serializing/deserializing. Doing heavy work often means working with a huge set of data- which means the cost of passing that data via messages scales with the benefits of parallelizing the work.
hinkley•2h ago
I think the clues are all there in the MDN docs for web workers. Having a worker act as a forward proxy for services; you send it a URL, it decides if it needs to make a network request, it cooks down the response for you and sends you the condensed result.

Most tasks take more memory in the middle that at the beginning and end. And if you're sharing memory between processes that can only communicate by setting bytes, then the memory at the beginning and end represents the communication overhead. The latency.

But this is also why things like p-limit work - they pause an array of arbitrary tasks during the induction phase, before the data expands into a complex state that has to be retained in memory concurrent with all of its peers. By partially linearizing you put a clamp on peak memory usage that Promise.all(arr.map(...)) does not, not just the thundering herd fix.

dwattttt•2h ago
Now to just write the processing code in something that compiles to WebAssembly, and you can start copying and sending ArrayBuffers to your workers!

Or I guess you can do it without the WebAssembly step.

MutedEstate45•3h ago
I really like seeing the segmented buffer approach. It's basically the rope data structure trick I used to hand-roll in userland with libraries like fast-json-stringify, now native and way cleaner. Have you run into the bailout conditions much? Any replacer, space, or custom .toJSON() kicks you back to the slow path?
jonas21•2h ago
The part that was most surprising to me was how much the performance of serializing floating-point numbers has improved, even just in the past decade [1].

[1] https://github.com/jk-jeon/dragonbox?tab=readme-ov-file#perf...

iouser•2h ago
Did you run any tests/regressions against the security problems that are common with parsers? Seems like the solution might be at risk of creating CVEs later
taeric•2h ago
I confess that I'm at a bit of a loss to know what sort of side effects would be common when serializing something? Is there an obvious class of reasons for this that I'm just accidentally ignoring right off?
vinkelhake•1h ago
A simple example is `toJSON`. If an object defines that method, it'll get invoked automatically by JSON.stringify and it could have arbitrary side effects.

I think it's less about side effects being common when serializing, just that their fast path avoids anything that could have side effects (like toJSON).

The article touches briefly on this.

kevingadd•54m ago
Calling a property getter can have side effects, so if you serialize an object with a getter you have to be very cautious to make sure nothing weird happens underneath you during serialization.

People have exploited this sort of side effect to get bug bounties before via type confusion attacks, iirc.

monster_truck•1h ago
I don't think v8 gets enough praise. It is fucking insane how fast javascript can be these days
andyferris•1h ago
Yeah, it is quite impressive!

It's a real example of "you can solve just about anything with a billion dollars" though :)

I'd prefer JavaScript kept evolving (think "strict", but "stricter", "stricter still", ...) to a simpler and easier to compile/JIT language.

ayaros•36m ago
Yes, this is what I want too. Give me "stricter" mode.
fngjdflmdflg•2m ago
I want JS with sound types. It's interesting how sound types can't be added to JS because runtime checks would be too expensive, but then so much of what makes JS slow is having to check types all the time anyway, and the only way to speed it up is to retroactively infer the types. I want types plus a "use typechecked" that tells the VM I already did some agreed upon level of compile-time checks and now it only needs to do true runtime checks that can't be done at compile time.
ot•56m ago
The SWAR escaping algorithm [1] is very similar to the one I implemented in Folly JSON a few years ago [2]. The latter works on 8 byte words instead of 4 bytes, and it also returns the position of the first byte that needs escaping, so that the fast path does not add noticeable overhead on escape-heavy strings.

[1] https://source.chromium.org/chromium/_/chromium/v8/v8/+/5cbc...

[2] https://github.com/facebook/folly/commit/2f0cabfb48b8a8df84f...

pyrolistical•46m ago
> Optimizing the underlying temporary buffer

So array list instead of array?

greatgib•31m ago
An important question that was not addressed is whether the general path will be slower to account for what is needed to check first if the fast path can be used.
lifthrasiir•5m ago
As usual, the advancement in double-to-string algorithms is usually driven by JSON (this time Dragonbox).

Show HN: I spent 6 years building a ridiculous wooden pixel display

https://benholmen.com/blog/kilopixel/
640•benholmen•7h ago•94 comments

Is It FOSS?

https://isitreallyfoss.com/
63•exiguus•2h ago•11 comments

Qwen-Image: Crafting with native text rendering

https://qwenlm.github.io/blog/qwen-image/
247•meetpateltech•7h ago•73 comments

NASA's Curiosity picks up new skills

https://www.jpl.nasa.gov/news/marking-13-years-on-mars-nasas-curiosity-picks-up-new-skills/
76•Bluestein•4h ago•24 comments

AWS European Sovereign Cloud to be operated by EU citizens

https://www.aboutamazon.eu/news/aws/aws-european-sovereign-cloud-to-be-operated-by-eu-citizens
44•pulisse•2h ago•35 comments

How we made JSON.stringify more than twice as fast

https://v8.dev/blog/json-stringify
132•emschwartz•9h ago•22 comments

What Does One Billion Dollars Look Like?

https://whatdoesonebilliondollarslooklike.website/
21•alexrustic•1h ago•13 comments

Indian Sign Painting: A typeface designer's take on the craft

https://bl.ag/indian-sign-painting-a-typeface-designers-take-on-the-craft/
100•detaro•2d ago•16 comments

Content-Aware Spaced Repetition

https://www.giacomoran.com/blog/content-aware-sr/
60•ran3000•3h ago•15 comments

Show HN: I've been building an ERP for manufacturing for the last 3 years

https://github.com/crbnos/carbon
5•barbinbrad•1h ago•0 comments

Job-seekers are dodging AI interviewers

https://fortune.com/2025/08/03/ai-interviewers-job-seekers-unemployment-hiring-hr-teams/
474•robtherobber•15h ago•728 comments

EconTeen – Financial Literacy Lessons and Tools for Teens

https://econteen.com/
4•Chrisjackson4•20m ago•1 comments

Hiroshima (1946)

https://www.newyorker.com/magazine/1946/08/31/hiroshima
25•pseudolus•2d ago•17 comments

OpenIPC: Open IP Camera Firmware

https://openipc.org/à
180•zakki•3d ago•105 comments

Once a death sentence, cardiac amyloidosis is finally treatable

https://www.nytimes.com/2025/08/04/well/cardiac-amyloidosis.html
74•elektor•3h ago•2 comments

Cellular Starlink expands to support IoT devices

https://me.pcmag.com/en/networking/31452/spacexs-cellular-starlink-expands-to-support-iot-devices
57•teleforce•3d ago•38 comments

DrawAFish.com Postmortem

https://aldenhallak.com/blog/posts/draw-a-fish-postmortem.html
220•hallak•11h ago•52 comments

How we built Bluey’s world

https://www.itsnicethat.com/features/how-we-built-bluey-s-world-cartoon-background-scenery-art-director-catriona-drummond-animation-090725
299•skrebbel•3d ago•136 comments

Perplexity is using stealth, undeclared crawlers to evade no-crawl directives

https://blog.cloudflare.com/perplexity-is-using-stealth-undeclared-crawlers-to-evade-website-no-crawl-directives/
900•rrampage•9h ago•522 comments

What Can a Cell Remember?

https://www.quantamagazine.org/what-can-a-cell-remember-20250730/
42•chapulin•4d ago•4 comments

A deep dive into Rust and C memory interoperability

https://notashes.me/blog/part-1-memory-management/
127•hyperbrainer•8h ago•57 comments

Customizing tmux

https://evgeniipendragon.com/posts/customizing-tmux-and-making-it-less-dreadful/
75•EPendragon•7h ago•71 comments

My Ideal Array Language

https://www.ashermancinelli.com/csblog/2025-7-20-Ideal-Array-Language.html
109•bobajeff•10h ago•49 comments

Show HN: Sidequest.js – Background jobs for Node.js using your database

https://docs.sidequestjs.com/quick-start
42•merencia•7h ago•10 comments

Read your code

https://etsd.tech/posts/rtfc/
155•noeclement•9h ago•89 comments

Century-old stone “tsunami stones” dot Japan's coastline (2015)

https://www.smithsonianmag.com/smart-news/century-old-warnings-against-tsunamis-dot-japans-coastline-180956448/
124•deegles•10h ago•43 comments

Objects should shut up

https://dustri.org/b/objects-should-shut-the-fuck-up.html
263•gm678•8h ago•201 comments

Show HN: Tiny logic and number games I built for my kids

https://quizmathgenius.com/
66•min2bro•8h ago•25 comments

Is the interstellar object 3I/ATLAS alien technology? [pdf]

https://lweb.cfa.harvard.edu/~loeb/HCL25.pdf
70•jackbravo•10h ago•94 comments

Circadian justice (2022)

https://eprints.lse.ac.uk/112431/
54•anigbrowl•5h ago•21 comments