-
Type: Improvement
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: BSON
During extensive benchmarking of BSON serialization/deserialization performance to test NODE-6246 I found that most document properties cause multiple calls to `Object.prototype.toString.call(prop)` which are quite expensive. By refactoring the serialization checks to move these calls out of hot paths could result in ~20% serialization performance (testing with MFlix dataset). By also integrating a WeakMap cache to essentially memoize calls to `Object.prototype.toString.call(prop)` can increase performance of serialization and calculateSize to 20-40%.