I am trying to understand BSON in-depth. I read a few informative questions such as: Why is JSON faster than BSON in node.js?, Which one is lighter, JSON or BSON?. But I still do not understand what makes BSON traversal is faster than JSON.
As per https://bsonspec.org/faq.html ,
BSON is also designed to be fast to encode and decode. For example, integers are stored as 32 (or 64) bit integers, so they don't need to be parsed to and from text. This uses more space than JSON for small integers, but is much faster to parse.
I was under the assumption that computers store everything in binary. Why is this special?
FAQ document (above) also provides an example of BSON, but reading it I am not able to grasp why BSON is faster than JSON? Are they looking for some beginning & end characters that are BSON specific & are missing in JSON, which helps with fast traversal?
{"hello": "world"}
ā
\x16\x00\x00\x00 // total document size
\x02 // 0x02 = type String
hello\x00 // field name
\x06\x00\x00\x00world\x00 // field value
\x00 // 0x00 = type EOO ('end of object')
{"BSON": ["awesome", 5.05, 1986]}
ā
\x31\x00\x00\x00
\x04BSON\x00
\x26\x00\x00\x00
\x02\x30\x00\x08\x00\x00\x00awesome\x00
\x01\x31\x00\x33\x33\x33\x33\x33\x33\x14\x40
\x10\x32\x00\xc2\x07\x00\x00
\x00
\x00
BSON parsing is faster than JSON due to its binary format, explicit type information, compactness, reduced preprocessing, and efficient data structures.