4 ms·
This is false, I've optimized horrendously large json parsing by simply rotating the data in a table form and using a binary serializer/deserializer (c.js provi
by secondaryacct 5y ago
This is false, I've optimized horrendously large json parsing by simply rotating the data in a table form and using a binary serializer/deserializer (c.js provided by kdb: https://github.com/KxSystems/kdb/blob/master/c/c.js https://github.com/KxSystems/kdb/blob/master/c/c.js ).
It's insanely faster to parse binary into js object without going through json at all than parsing string json, and we transformed a dumb application from slow death to "oh wow no need to optimize further, all perf problems are now fixed" simply by switching the serialization format (faster to download, faster to deserialize, faster to access).
It even helps the backend to serialize faster than writing enormous ASCII strings just to talk to the browser memory structure. Dont forget these json format are just better xml and still made for humans. Machines can work well with structures closer to the memory layout, for instance sending the header once and subsequent objects in ordered attributes with separator is closer to how an object is stored and accessed by JS.
I suppose a mistake we all make after years of JSON is thinking it represents objects for the browser but an object is always a byte array with an offset per attribute descriptor. So send the attribute descriptors and their type (which will describe a size too) first and then just fill.
- ninkendo 5y ago> I suppose a mistake we all make after years of JSON is thinking it represents objects for the browser but an object is always a byte array with an offset per attribute descriptor. Doesn’t this depend on the language? Plenty of languages implement “objects” as a hash table underneath, with properties just being keys. In fact I think most JavaScript engines even work this way, at least until some amount of JIT optimization happens to start assigning static offsets to known keys (I believe this was one of v8’s advancements when Chrome first came out.)
- MaxBarraclough 5y agoAre there any good benchmarks for deserialization performance with JSON/FlatBuffers/etc across the major JavaScript engines? I was surprised I couldn't find one with a quick search.