-
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-6344): Improve ObjectId.isValid(string) performance #708
Conversation
Not sure if you wanted a Jira created since this is such a small change, but I could create one if necessary. |
Hey @SeanReece - I don't believe we have benchmarks for this method. Could you share your benchmarking script so I can test and reproduce? |
@baileympearson Sure thing. I just threw together a simple benchmark since I can't get bson-bench to run. If you pull this branch locally, change the name in
|
@SeanReece Thanks - I see the same behavior. I'll bring this up with the team later this week. |
c5fc927
to
bc20e7a
Compare
@SeanReece just as the other PR for isValid I've rebased this one as well. |
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.
Now we do have benchmarks merged for this helper! Also we're better set up to add any helper to our CI so after it is improved we can check if any future changes regress it or make it better. (check out test/bench/custom/readme.md if you're curious)
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.
LGTM!
Description
This MR improves performance of using
ObjectId.isValid('some string')
to check if a string is a valid hex representation of an ObjectId. We frequently call this function to check if a user's input is valid (for example, when creating a document that links to other document(s)).Performance tests
There is a drastic performance improvement when checking for invalid strings since throwing/catching errors is expensive.
What is changing?
Is there new documentation needed for these changes?
None
What is the motivation for this change?
Release Highlight
ObjectId.isValid(string)
performance improvementOften used to validate whether a hex string is the correct length and proper format before constructing an ObjectId for querying, the isValid function will validate strings much faster than before.
Double check the following
npm run check:lint
scripttype(NODE-xxxx)[!]: description
feat(NODE-1234)!: rewriting everything in coffeescript