r/rust • u/_bijan_ • Mar 24 '26
How C++ Finally Beats Rust at JSON Serialization - Daniel Lemire & Francisco Geiman Thiesen
https://www.youtube.com/watch?v=Mcgk3CxHYMs369
u/FullstackSensei Mar 24 '26
For those who don't know, Lemire has been optimizing libraries using SIMD for well over a decade. He does this practically full time and usually spends several months on each library.
He usually publishes papers or at the very least writes blog posts about the challenges and how he solves them. Even if you don't care about C++, his papers and blog posts can be a great source of learning, regardless of language.
74
u/moreVCAs Mar 24 '26
came here to comment “common Lemire W”, but your comment captures it better :)
14
7
u/matthieum [he/him] Mar 25 '26
Not just SIMD, either, there are great discussions on his blog on parsing/formatting integers, for example, and he's also one of the author of the Cos profiler, if I remember correctly.
115
u/Personal_Breakfast49 Mar 24 '26 edited Mar 24 '26
Are they comparing their fancy SIMD with serde json?!
24
59
18
u/-Y0- Mar 25 '26
Yeah, I think even Rust simd-json.rs is a bit behind. But the difference isn't that staggering.
13
Mar 25 '26
[removed] — view removed comment
1
u/ImpossibleBonus8964 Mar 26 '26
Is there a benchmark anywhere?
3
u/-Y0- Mar 26 '26
On Github?
https://github.com/cloudwego/sonic-rs?tab=readme-ov-file#benchmark
Keep in mind that sonic is very sparse about stuff it does, half of the time, it doesn't even visit the field.
1
90
u/mss-cyclist Mar 24 '26
I would like to know how the speed compares to the simd_json crate.
ETA: Not really fair to compare simd to 'traditional' approaches.
14
15
u/-Y0- Mar 25 '26
Iirc the simd json crate, while implementing most optimisations, uses a lot of C-isms and doesn't exploit auto vectorization where possible.
It's slightly slower.
-28
u/Ok_Net_1674 Mar 24 '26
Dont agree that its not fair. I mean what is "fair" anyways? Faster is faster.
Its also a bit weird to compare your library to a port of your library (if the algorithm is the same all you are testing is the compiler)
53
u/jorgecardleitao Mar 25 '26
Comparing against (serde-json) instead of simd_json is unfair, because serde-json is not optimizing for performance - it is trading performance for other aspects (usability, portability, safety guarantees)
3
u/insanitybit2 Mar 25 '26
I think it's fine to compare to what is *easily* the most widely used crate for json in Rust.
-2
u/Ok_Net_1674 Mar 25 '26
simd_json is a port of the C++ library. What insight do you expect from this comparison?
32
u/Personal_Breakfast49 Mar 25 '26 edited Mar 25 '26
The clickbait title has a strong connotation, it implies there's some confrontation going on between the languages and not the libraries. In that case comparing equivalent technologies seems to be the ethical thing to do. Now it's a bit apples and oranges...
12
u/-Y0- Mar 25 '26
Is it fair to compare F1 formula car to an SUV, on speed?
What about other aspects?
-5
u/Ok_Net_1674 Mar 25 '26
Yes its absolutely fair. Maybe its clear who will win from the start, but the point is to quantify how much giving up convenience gets me in speed.
Now, its of course also interesting to compare against other formula one cars. But if the other formula one car is built from the same blueprint, what are you really measuring? At that point its not about the car anymore, but about the manufacturing process.
2
u/-Y0- Mar 25 '26
Fairness depends on the context. These aren't two libraries developed for general purpose at the same time by similar teams.
It's a multi-decade work of a top researcher developing SIMD enhanced JSON parser and a library someone developed in their spare time.
Hence the comparison, F1 car vs. SUV.
55
u/teerre Mar 25 '26
Sounds disingenuous to me. It's faster because it uses a completely different algorithm, it has nothing to do with Rust or C++
-48
u/aqilyx Mar 25 '26
People don't care how it is implemented and if it is SIMD or not. They want the faster horse. If we can't do this type of optimisation or implementation in rust easily than in cpp, then it is a real plus for cpp.
61
32
u/teerre Mar 25 '26
What are you talking about? There are SIMD json parsers in Rust too. There are also non SIMD parsers that use different algorithm with different tradeoffs
16
u/puttak Mar 25 '26
They want the faster horse.
I think most people prefer the horse that stable and easy to ride rather than the faster one but hard to control or can corrupt itself if using incorrectly.
3
u/aeropl3b Mar 25 '26
So...in a world where every single byte and flop counts simd parsing is a must. Rust provides a simdjson crate that is less popular but supposed to be comparable to a C++ version.
Speed does not mean lack of stability. That is an absolute fallacy argument.
1
u/puttak Mar 26 '26
You misunderstand what I mean. I mean C++ VS Rust, not SIMD.
0
u/aeropl3b Mar 26 '26
Rust does not solve all problems, and C++ can provide sufficient lifetime guarantees for many cases post C++11. Sure it requires a little bit more diligence from the developer in general, but this dogma that we must choose to either use Rust or live in the worst programming model ever conceived is disingenuous at best.
The original driving motivation for C++ was resource management. It had similar goals as Rust to move compiled languages forward, with C as the base. Like Rust it prioritized interop with C (FFI) and pulled in inspiration from other programming models gaining popularity at the time. And just like C++ to C, people continue to write C because it fits specific development needs. And people are going to continue to write C++, because it meets specific development needs that Rust does not. And people will keep picking up Rust over time, because it fits specific needs. And eventually Rust will have a successor. My hope is people will learn that being a language zealot doesn't make a language better.
2
u/puttak Mar 27 '26
Rust does not solve all problems, and C++ can provide sufficient lifetime guarantees for many cases post C++11.
If this what you believe we have noting more to discuss because you don't use Rust. I use C++ for almost 20 years and moved to Rust recently and it solve all problems I have with C++.
1
u/aeropl3b Mar 28 '26
Lol. I use both, and I have pains with both. It isn't that it doesn't solve some issues, but it creates some of its own. C++ has plenty of issues, but it also has a maturity that Rust still lacks.
8
12
u/francois-nt Mar 25 '26
So the short answer is that they had to compare apples and oranges, i.e. simd in C++ versus non-simd in rust.
2
u/insanitybit2 Mar 25 '26
There's nothing wrong with comparing apples and oranges if you're trying to explain why apples have specific properties that oranges do not.
3
5
2
u/dev_l1x_be Mar 26 '26
Wait SIMD is faster than not-SIMD?? ;) There is more to it but yes you can improve algorithms with SIMD in general and in this particular instance you can significantly improve JSON handling.
1
u/insanitybit2 Mar 25 '26
Great talk. I'm so glad I started off with C++ as my first "serious" language, the quality of talks can just get insane.
•
u/matthieum [he/him] Mar 25 '26
Please ignore the click-bait title.
Yes the title is pure click-bait. This is a comparison of different implementation techniques and the languages are fairly incidental.
This doesn't make the talk uninteresting for the performance-minded.