News for hackers. Stuff that matters.
Re:Protobuf-ES: The Protocol Buffers TypeScript/JavaScript r... by dekhn on Monday October 31, 2022 @11:16AM (#33406977)
protobuf parsing is far faster- it's a binary protocol. The underlying code is highly optimized and has to handle about 1/10th the total bytes. In computer, reducing memory access is often the best way to optimize.

PB can always be decoded to a text representation if you need to inspect it.

Re:Protobuf-ES: The Protocol Buffers TypeScript/JavaScript r... by mmis1000 on Monday October 31, 2022 @12:05PM (#33407745)
JS __is__ dumb at handling binary. The overhead is significant. The first thing to do when optimizing a Nodejs program is always replace loops that iterate through individual byte of binary with some native(wasm?) equivalent. JSON on the other hand isn't affected by this overhead. Because JSON.parse is a native method on every platform.

I once doing a mixing of two buffers that contains PCM. A simple task that take two number, average and put into another buffer. The native implementation is about 10x fast than the one I wrote with JS (Or consume 10X less cpu time).

A native Protobuf is definitely going to beat a native JSON implementation. A JS Protobuf if also likely to beat a JS JSON implementation.

But a JS Protobuf to native JSON? I doubt.

Re:Protobuf-ES: The Protocol Buffers TypeScript/JavaScript r... by lucideer on Monday October 31, 2022 @12:56PM (#33408700)
Do you have any links showing protobuf is faster?

There's nothing in your comment that hadn't already been said before by sibling commenters but as far as I've seen in the real world JSON appears to be faster in practice. Which is all that counts.

Yours and the many other commenters making the same assumption (it's binary ergo it must be fast) make a really good case for PB's adoption being rooted in theoretical assumptions rather than real-world benefit.

I get it. It makes sense that it should be faster. Nothing is self evident though. You gotta measure it.

Re:Protobuf-ES: The Protocol Buffers TypeScript/JavaScript r... by afavour on Monday October 31, 2022 @01:14PM (#33409045)
> In our tests, it was demonstrated that this protocol performed up to 6 times faster than JSON.

https://auth0.com/blog/beating-json-performance-with-protobu...

Re:Protobuf-ES: The Protocol Buffers TypeScript/JavaScript r... by cldellow on Monday October 31, 2022 @01:23PM (#33409220)
The 6 times faster benchmark from that article is describing a Java server and Java client.

This thread is about protobuf vs JSON in a JavaScript environment.

The article you linked _does_ talk about JavaScript environments, too, but the numbers are much less impressive.

Re:Protobuf-ES: The Protocol Buffers TypeScript/JavaScript r... by dekhn on Monday October 31, 2022 @01:15PM (#33409066)
I don't really get your attitude here. In particular, I'm not disagreeing that JSON parsers in the browser could be currently faster than protocol buffers.

I'm saying that computer science and hardware dictate that protocol buffers are faster for a wide range of reasons. That part's not in question- smaller data encodings have better cache use, and require far fewer dictionary (hash table) lookups at parse time, as well as far length work parsing strings. If you want to argue against my point there I don't know what to say.

If it was a priority to write a blindingly fast protocol buffer parser in JS, it's almost certain than an expert could write a faster one than a similar JSON parser.

Re:Protobuf-ES: The Protocol Buffers TypeScript/JavaScript r... by lucideer on Tuesday November 01, 2022 @05:26AM (#33418827)
> I don't really get your attitude here

My attitude here is that I made a specific observation: JSON is likely to be faster or at least negligibly slower in browsers in practice.

Everyone is replying either with theoretical speed comparisons or server-to-server non-JavaScript benchmarks, which don't seem relevant to my very specific observation I made up top...

Re:Protobuf-ES: The Protocol Buffers TypeScript/JavaScript r... by yencabulator on Tuesday November 01, 2022 @12:52PM (#33423799)
If you had bothered to benchmark it, you'd have realized that lots of protobuf libraries are actually surprisingly slow.