3 ms·
at least in the frontend (without WASM), it depends. a few months ago i tested https://github.com/mapbox/pbf https://github.com/mapbox/pbf and while it was fas
by leeoniya 4y ago
at least in the frontend (without WASM), it depends.
a few months ago i tested https://github.com/mapbox/pbf https://github.com/mapbox/pbf and while it was faster for deep/complex structs vs an unoptimized/repetative JSON blob, it was much slower at shallow structs and flat arrays of stuff. if you spend a bit of time to encode stuff as flat arrays to avoid mem alloc, JSON parsing wins by a lot since it goes through highly optimized C or assembly, while decoding protobuf in the JS JIT does not.
of course it's not always feasible to make optimized over-the-wire JSON structs if you have a huge/complex API that can return many shapes of complex structs.
- mourner 4y agoAt pbf speeds, decoding is usually no longer a bottleneck, but bandwidth might be when comparing with gzipped JSON. Also, one of the primary advantages of pbf is being able to decode partially and lazily (and adjust how things are decoded at low level), which is very important in use cases like vector maps.
- leeoniya 4y ago> At pbf speeds, decoding is usually no longer a bottleneck, but bandwidth might be when comparing with gzipped JSON. we were streaming a few hundred float datapoints spread across a dozen(ish) flat arrays over websocket at 20-40hz and needed to decode the payload eagerly. plain JSON was a multi-factor speedup over pbf for this case. but it's fully possible i was holding it wrong, too! even when your "bottleneck" is rendering/rasterization (10ms), but your data pipe takes 3ms instead of 1ms, it's a big effect on framerate, battery, thermals, etc. i'm a big fan of your work! while i have you here, would you mind reviewing this sometime soon? ;) https://github.com/mourner/flatbush/pull/44 https://github.com/mourner/flatbush/pull/44