News for hackers. Stuff that matters.
Re:A new experimental Go API for JSON by analytically on Tuesday September 09, 2025 @12:44PM (#45184641)
Benchmark Analysis: Sonic vs Standard JSON vs JSON v2 in Go

https://github.com/centralci/go-benchmarks/tree/b647c45272c7...

Re:A new experimental Go API for JSON by gethly on Tuesday September 09, 2025 @02:00PM (#45185800)
Those numbers look similar to goccy. I used to use it in the past, even Kubernetes uses it as direct dependency, but the amount of issues have been stockpiling for quite some time so I no longer trust it.

So it seems both are operating at the edge of Go's capabilities.

Personally, I think JSON should be in Go's core and highly optimised simd c code and not in the Go's std library as standard Go code. As JSON is such an important part of the web nowadays, it deserves to be treated with more care.

Re:A new experimental Go API for JSON by CamouflagedKiwi on Tuesday September 09, 2025 @03:24PM (#45187400)
Agreed. goccy has better performance most times but absolutely appalling worst-case performance which renders it unacceptable for many use cases - in my case even with trusted input it took effectively eternity to decode it. It's literally a quadratic worst case, what's the point of having a bunch of super clever optimisations if the big-O performance is that bad.

Sonic may be different but I'm feeling once bitten twice shy on "faster" JSON parsers at this point. A highly optimised SIMD version might be nice but the stdlib json package needs to work for everything out there, not just the cases the author decided to test on, and I'd be a lot more nervous about something like that being sufficiently well tested given the extra complexity.

Re:A new experimental Go API for JSON by tptacek on Tuesday September 09, 2025 @02:15PM (#45186068)
What does "highly optimized" have to do with whether it's in the standard library? Highly-optimized cryptography is in the standard library.
Re:A new experimental Go API for JSON by ronsor on Tuesday September 09, 2025 @02:20PM (#45186161)
Not to mention that Go is never going to put C code in the standard library for anything portable. It's all Go or assembly now.
Re:A new experimental Go API for JSON by dwattttt on Tuesday September 09, 2025 @07:57PM (#45191230)
It's amusing to see assembly considered more portable than C.
Re:A new experimental Go API for JSON by jitl on Tuesday September 09, 2025 @09:45PM (#45192065)
No, portable code is written in Go, not C. Platform specific code is written in ASM.
Re:A new experimental Go API for JSON by pjmlp on Wednesday September 10, 2025 @04:31AM (#45194857)
Which is the right approach, and one of the areas I actually appreciate the work of Go authors.

There is nothing special about C, other that its historical availability after UNIX's free beer came to be.

Any combination of high level + Assembly is enough.

Re:A new experimental Go API for JSON by dilyevsky on Tuesday September 09, 2025 @02:59PM (#45186976)
Previously Go team has been vocal about sacrificing performance to keep stdlib idiomatic and readable. Guess the crypto packages are the exception because they are used heavily by Google internally and json and some others (like say image/jpeg which had crap performance last time i checked) are not.

Edit: See: https://go.dev/wiki/AssemblyPolicy

Re:A new experimental Go API for JSON by karel-3d on Wednesday September 10, 2025 @04:59AM (#45195083)
sonic uses a clang-generated ASM, built from C (transformed from normal clang-generated ASM to "weird" go ASM via python script)... I don't think this will be in standard library.
Re:A new experimental Go API for JSON by nasretdinov on Tuesday September 09, 2025 @02:34PM (#45186485)
Go doesn't yet have native SIMD support, but it actually might in the future: https://github.com/golang/go/issues/73787

I think when it's introduced it might be worth discussing that again. Otherwise providing assembly for JSON of all packages seems like a huge maintenance burden for very little benefit for end users (since faster alternatives are readily available)

Re:A new experimental Go API for JSON by kristianp on Thursday September 11, 2025 @06:41PM (#45216838)
Interesting that the proposal is for low-level intrinsics as well as a non-processor-specific api: > Our plan is to take a two-level approach: Low-level architecture-specific API and intrinsics, and a high-level portable vector API. The low-level intrinsics will closely resemble the machine instructions (most intrinsics will compile to a single instruction), and will serve as building blocks for the high-level API.
Re:A new experimental Go API for JSON by godisdad on Tuesday September 09, 2025 @04:23PM (#45188360)
> As JSON is such an important part of the web nowadays, it deserves to be treated with more care.

There is a case to be made here but Corba, SOAP and XML-RPC likely looked similarly sticky and eternal in the past

Re:A new experimental Go API for JSON by mdaniel on Tuesday September 09, 2025 @10:12PM (#45192272)
I hear you, but I am not aware of anyone that tried XMLHttpRequest.send('<s:Envelope xmlns:s...') or its '<methodCall>' friend from the browser. I think that's why they cited "of the web" and not "of RPC frameworks"
Re:A new experimental Go API for JSON by pjmlp on Wednesday September 10, 2025 @05:30AM (#45195292)
No, because that was server's job on the endpoint.
Re:A new experimental Go API for JSON by int_19h on Wednesday September 10, 2025 @02:50AM (#45194160)
I don't recall either CORBA or SOAP ever seeing enough penetration to look "eternal" as mainstream tech goes (obviously, and especially with SOAP, there's still plenty of enterprise use). Unlike XML and JSON.
Re:A new experimental Go API for JSON by pjmlp on Wednesday September 10, 2025 @05:29AM (#45195284)
They surely were, for anyone doing enterprise during the 2000's.

We had no plans to change to something else.

Re:A new experimental Go API for JSON by int_19h on Thursday September 11, 2025 @05:59PM (#45216546)
I recall a lot of talk about CORBA in early 00s, but I don't think I've actually ever seen it used anywhere outside of Gnome.

By late 00s, even the talk was more along the lines of it being legacy tech.

Re:A new experimental Go API for JSON by pjmlp on Friday September 12, 2025 @10:42AM (#45222669)
Several Nokia Networks products were based on CORBA, running on HP-UX, in a mix of C++ and Perl.

Eventually migrated to Java EE, also taking advantage of CORBA compatibility.

Re:A new experimental Go API for JSON by SSLy on Monday September 15, 2025 @08:54AM (#45249087)
Q3 is still in C++. Huawei also still supports CORBA.
Re:A new experimental Go API for JSON by andreasmetsala on Wednesday September 10, 2025 @05:36AM (#45195328)
Eternal or not, right now JSON is used everywhere which means the performance gains of a more optimized Stalin would be significant. Just because we don’t know if JSON is around in 10 years doesn’t mean we should settle for burning extra compute on it.
Re:A new experimental Go API for JSON by ForHackernews on Tuesday September 09, 2025 @06:17PM (#45190096)
The fact that JSON is used so commonly for web stuff seems like an argument against wasting your time optimizing it. Network round trip is almost always going to dominate.

If you're pushing data around on disk where the serialization library is your bottleneck, pick a better format.

Re:A new experimental Go API for JSON by catlifeonmars on Tuesday September 09, 2025 @09:19PM (#45191881)
You’re assuming request-response round trip between each call to encode/decode. Streaming large objects/NDJSON would still have serialization bottleneck. (See elasticsearch/opensearch for a real life use case)

But in that case your last point still stands: pick a better format

Re:A new experimental Go API for JSON by gethly on Wednesday September 10, 2025 @02:59AM (#45194217)
There is no better human-readable format. I looked. The only alternative i considered was Amazon Ion but it proved to bring no additional value compared to json.
Re:A new experimental Go API for JSON by kbolino on Wednesday September 10, 2025 @11:32AM (#45199210)
This is an interesting perversion of Amdahl's law.

Yes, if you are looking at a single request-response interaction over the Internet in isolation and observing against wall clock time, the time spent on JSON (de-)serialization (unless egregiously atrocious) will usually be insignificant.

But that's just one perspective. If we look at CPU time instead of wall clock time, the JSON may dominate over the network calls. Moreover, in a language like Go, which can easily handle tens to hundreds of thousands of parked green threads waiting for network activity, the time spent on JSON can actually be a significant factor in request throughput. Even "just" doubling RPS from 10k to 20k would mean using half as much energy (or half as much cloud compute spend etc.) per request.

Changing formats (esp to a low-overhead binary one) might yield better performance still, but it will also have costs, both in time spent making the change (which could take months) and adapting to it (new tools, new log formats, new training, etc.).

Re:A new experimental Go API for JSON by ForHackernews on Thursday September 11, 2025 @06:04AM (#45209753)
If you're optimizing for energy wasted serving your website you could stop sending 10 megs of garbage javascript on page load.
Re:A new experimental Go API for JSON by tgv on Tuesday September 09, 2025 @01:17PM (#45185163)
IIRC, sonic does JIT, has inline assembly (github says 41%), and it's huge. There's no way you can audit it. If you don't need to squeeze every cpu cycle out of your json parser (and most of us don't; go wouldn't be the first choice for such performance anyway), I'd stick with a simpler implementation.
Re:A new experimental Go API for JSON by jitl on Tuesday September 09, 2025 @11:17PM (#45192785)
It also seems to need 4x the memory
Re:A new experimental Go API for JSON by kiitos on Tuesday September 09, 2025 @05:29PM (#45189474)
first of all, that doesn't exercise JSON v2 at all, afaict

second of all, sonic apparently uses unsafe to (unsafe-ly) cast byte slices to strings, which of course is gonna be faster than doing things correctly, but is also of course incomparable to doing things correctly

like almost all benchmark data posted to hn -- unsound, ignore

Re:A new experimental Go API for JSON by kristianp on Tuesday September 09, 2025 @07:01PM (#45190627)
Just using the GOEXPERIMENT=jsonv2 compiler flag changes the underlying implementation if you don't change any code. You're still using the less correct and efficient API though.
Re:A new experimental Go API for JSON by Thaxll on Tuesday September 09, 2025 @05:58PM (#45189848)
And Sonic with its "cutting edge" optimization is still slower than std Json on arm64 with basic use cases. It shows that JIT, simd, low level code comes at cost of maintenance for all platform.

https://github.com/bytedance/sonic/issues/785