-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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: add isSimpleValidator #11412
perf: add isSimpleValidator #11412
Conversation
If we combine this with #11408 we get super performance speed for validation :D |
With the improved benchmark from #11415 before:
after:
|
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 👍
*/ | ||
const isSimpleValidatorCache = new WeakMap(); | ||
|
||
module.exports = function isSimpleValidator(obj) { |
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 request would be to get rid of the caching. I know that it should be faster and the risk of WeakMap()
causing any sort of memory issue is extremely low, but I'd rather write off that risk altogether and just keep this as a simple loop.
I'll merge this and remove the WeakMap caching locally |
Seems like the performance is still very good. Strange. Expected a higher performance penalty. But hey, i dont complain. |
This PR adds a helper method called isSimpleValidator. Basically it is a function to determine if a validator is just a simple object or if it is a more complex one. To avoid the usage in other places, it is not named isFlatObject. It uses a WeakMap to cache the result and gain as such speed.
With isSimpleValidator we determine if we should make a deep clone of the validator or a shallow copy of it with Object.assign.
Before:
after
So we basically double the performance on the valid path.