-
Notifications
You must be signed in to change notification settings - Fork 254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(NODE-5363): defer byte slicing to utf8 decoding API in nodejs #585
Conversation
…om:mongodb/js-bson into NODE-5358/implement-bson-perf-improvements
Hi @W-A-James, Is there any way we can help you on those performance changes ? |
Hi @billouboq, thanks for your interest in this work! The work in this PR specifically is focused on string deserialization, but we are interested in investigating more about bson performance in general. We would be interested in investigating:
Any investigation into any one of the areas listed above would be very useful. If you identify any new areas that could be improved and have suggestions on how to do so, filing a ticket on the NODE project with your findings would be the best way to inform us about your findings and allow us to take action on them. As for the benchmarks we currently have, they live in
This pr adds similar benchmarks for Int32 and Long deserialization.
|
Description
What is changing?
ByteUtils
ByteUtils.toUTF8
toUTF8: (buffer: Uint8Array) => string
->toUTF8: (buffer: Uint8Array, start: number, end: number) => string
ByteUtils.toUTF8
to takestart
andend
parameters and pass them intoBuffer.toString
directlyByteUtils.toUTF8
to takestart
andend
parameters and pass them intoUint8Array.slice
deserializer
Buffer.subarray
which was one source of performance degradationBenchmarks
Performance
This PR is meant to address a performance regression that was introduced in v4.6.0 during the introduction of our
ByteUtils
functions.The benchmark used to assess performance is the
deserialize a large batch of documents each with an array of many strings
benchmark inetc/benchmarks/main.js
. The benchmark was run 100 times on v4.6, v5.3(latest as at time of writing) and with the changes made in this PR.The chart below shows the percent increase in runtime (lower is better) over v4.6. It clearly shows the difference in performance between v5.3 and v4.6 with the
local
column displaying marked improvement over v5.3. Note that there are still performance gains to be made before we are once again on par with v4.6.Is there new documentation needed for these changes?
No
What is the motivation for this change?
Increasing bson and driver performance
Release Highlight
Improved BSON UTF8 Decoding Performance
In the v5 major release of BSON we internally abstracted the different byte manipulation APIs used based on whether the library is running in Node.js or in a browser. This abstraction required us to create a
subarray
before invoking the environment's UTF8 decoding API. Creating the subarray before invoking Node.js'Buffer.prototype.toString
API turns out to cause an unnecessary slow down (See #585 for our research).Double check the following
npm run lint
scripttype(NODE-xxxx)[!]: description
feat(NODE-1234)!: rewriting everything in coffeescript