Why is JSON faster than BSON in node.js?

前端 未结 3 1486
礼貌的吻别
礼貌的吻别 2020-12-17 17:49

After reading this, there is a quote that stood out:

BSON is also designed to be fast to encode and decode. For example, integers are stored as 32 (or

3条回答
  •  青春惊慌失措
    2020-12-17 18:45

    I believe Node.js and most browsers are the exception.

    The simple answer is the JSON parser/serializer/deserializer (i.e. V8) are extremely optimized and are written in C/C++. The BSON parser is written in JavaScript. But even if the parser is written native (and I believe BSON has one) JSON still will probably win given how optimized V8 is for JSON.

    If you use a platform like Java or C# the BSON format is probably going to be faster.

    See @Matthais247 who answered after me but much more completely.

提交回复
热议问题