perf(NODE-4194): improve objectId constructor performance#498
Conversation
addaleax
left a comment
There was a problem hiding this comment.
@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 :)
durran
left a comment
There was a problem hiding this comment.
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
BSON@4.6.3
deserialize({ oid, string }, { validation: { utf8: false } }) takes 0.00303077ms on average
new Oid(buf) take 0.00059272ms on average
BSON@1.1.6
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
BSON@4.6.3
deserialize({ oid, string }, { validation: { utf8: false } }) takes 0.00150312ms on average
new Oid(buf) take 0.00020934ms on average
BSON@1.1.6
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.fromcall.What is the motivation for this change?
Improve the performance of creating an ObjectId from a buffer.
Double check the following
npm run lintscript<type>(NODE-xxxx)<!>: <description>