3 ms·
> Slower: ...every object in a hash...10x faster. Did you measure the 10x faster? Anyway, the dictionary is only needed on serialization, and then you only n
by mpweiher 10y ago
> Slower: ...every object in a hash...10x faster.
Did you measure the 10x faster?
Anyway, the dictionary is only needed on serialization, and then you only need an identity dictionary, which tends to be quite fast as it is only hashing the pointers. Deserialization only needs an array, with negligible overhead.
Furthermore, with JSON you tend to decode/encode via temporary dictionary representations anyway, which is many times more expensive when you're starting from an object representation. Going to an object representation also often materializes a full array/dictionary rep. because that's what the JSON specifies. You only figure out objects afterward.
So in my estimation, this has the potential of being significantly faster than typical JSON en-/de-coders.
[Background: I worked on XML parsing for a while, and having the tag preceding the contents was invaluable in creating efficient parsers that do not require a generic intermediate representation. Such generic intermediate representations typically do eat around 10x performance. See https://github.com/mpw/Objective-XML/tree/master https://github.com/mpw/Objective-XML/tree/master
Although the first time I noticed about the effects of generic intermediate representations was parsing Display Postscript's Binary Object Sequences generated from a PS->PDF distiller written in Postscript to graphical objects]
- rurban 10y agoYes, otherwise I wouldn't come up with such numbers. I maintain several such serializers with various feature sets. Yes, only serialization would be slow. Yes, going directly to objects would be faster also. YAML or native serializers do that. But your estimation is flawed. Fastest are still special pre-compiled serializers, such as protobuf, or better variants thereof which can mmap directly native objects. then binary serializers such as messagepack or the insecure bson because of compression. then json because of simplicity and limited recursion. then the dynamic monsters, which support references and objects.