-
Notifications
You must be signed in to change notification settings - Fork 253
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-4194): improve objectId constructor performance #498
Conversation
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.
@nbbeeken I don’t see any downsides in terms of correctness. I remember that instanceof
could be quite slow on some older-but-not-that-old V8 versions, so it might be worth checking the performance impact across Node.js versions.
In the long run, I think the best solution would be to just use Uint8Array everywhere anyway :)
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.
My only comment would be to up the iterations in the benchmark to get a more accurate representation of performance once it's warmed up. Here are the differences on my machine on 10.000 vs 1.000.000 iterations - it's far less of a discrepancy.
Iterations: 10000
BSON@current local
deserialize({ oid, string }, { validation: { utf8: false } }) takes 0.00283865ms on average
new Oid(buf) take 0.00018213ms on average
[email protected]
deserialize({ oid, string }, { validation: { utf8: false } }) takes 0.00303077ms on average
new Oid(buf) take 0.00059272ms on average
[email protected]
deserialize({ oid, string }, { validation: { utf8: false } }) takes 0.00203647ms on average
new Oid(buf) take 0.00031121ms on average
Iterations: 1000000
BSON@current local
deserialize({ oid, string }, { validation: { utf8: false } }) takes 0.00206223ms on average
new Oid(buf) take 0.00013110ms on average
[email protected]
deserialize({ oid, string }, { validation: { utf8: false } }) takes 0.00150312ms on average
new Oid(buf) take 0.00020934ms on average
[email protected]
deserialize({ oid, string }, { validation: { utf8: false } }) takes 0.00098606ms on average
new Oid(buf) take 0.00014574ms on average
What did you use to bench? |
@durran I bumped the iterations and I added system info print out
|
Hello! Is there a planned date for the next release of the package? Waiting for this performance improvement to be shipped to release a different update in another project so just curious if there is a timeline |
@harrisonhunter The improvement is now available in v4.6.4 🚀 |
Awesome! Thank you very much |
Description
What is changing?
Gating ensureBuffer with an instanceof check should avoid the reletively expensive
Buffer.from
call.What is the motivation for this change?
Improve the performance of creating an ObjectId from a buffer.
Double check the following
npm run lint
script<type>(NODE-xxxx)<!>: <description>