Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
perf(NODE-6246): Significantly improve memory usage and performance of ObjectId #703
perf(NODE-6246): Significantly improve memory usage and performance of ObjectId #703
Changes from all commits
8986b69
4c5d5dc
1f07ba1
296ac15
21dc61d
80526c7
b858ab1
32e0a9b
639cc3c
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the motivation for moving this step up here? seems like it may have broken the version check that comes later for this
BSONType
, unless I'm mistaken?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did see a measurable performance gain by moving the ObjectId check to the top
if
in my testing, I believe since some of those checks likeisUInt8Array()
andSymbol.for("@@mdb.bson.version")
are moderately expensive for such a hot path. Now that I'm thinking about this we can instantiate a single Symbol variable and just reference it instead of creating it every time, and maybe move theisUInt8Array()
down lower if that doesn't break any tests.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: I narrowed the performance impact to the
isUint8Array()
,isRegExp()
, andisDate()
calls, which all invokeObject.prototype.toString.call(value)
which is expensive. Did some refactoring and was able to get serialize from2.4m ops/sec
->3m ops/sec
, which in my testing is only about -8% decrease in raw serialization perf. AND all the tests are passing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A shared copy of the symbol sounds like a good call. As long as the version check is still performed, moving probably the most common BSON type into a position where it performs better sounds good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this call
.subarray
on the unint8Array with start/end? Otherwise won't this return a different result than the Node.js version of this API?