-
Type: Improvement
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 5.0.0, 5.1.0, 5.2.0, 5.3.0, 5.4.0, 5.5.0, 5.6.0
-
Component/s: BSON
Background
There was a severe performance regression in string deserialization introduced in bson v5 (https://docs.google.com/spreadsheets/d/1Wogm3APTMcZJK4BjXVx5xTaIGQkrtr38GzP89Nd3FV8/edit?usp=sharing) which is related to the implementation of ByteUtils.toUTF8 which is called primarily by getValidatedString in src/parser/deserializer.ts (see flamegraph below.) This issue affects all currently released versions of the driver starting from v5.0.0 which is where the dependency on bson v5 was added.
Unknowns
- What would the impact of trying to reduce/eliminate calls to ByteUtils.toLocalBufferType?
- How difficult will it be to get the Typescript to work as we'd like it to if we remove ByteUtils.toLocalBufferType calls?
Acceptance Criteria
- Update ByteUtils.toUTF8 in src/utils/node_byte_utils.ts to take in start and end and pass them through to the call to toString rather than calling Buffer.subarray directly inside getValidatedString.
- Address any typescript issues this causes
- Investigate how to reduce/eliminate calls to ByteUtils.toLocalBufferType in ByteUtils.toUTF8
- Audit the remainder of ByteUtils to investigate if there is anywhere else that we are taking an unnecessary performance hit
- Investigate best approach to adding regression tests specifically for the performance of getValidatedString and possibly of ByteUtils.toUTF8 and add these tests.