-
Notifications
You must be signed in to change notification settings - Fork 29.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
replace util.isType() with typeof #607
Comments
I'm interested in this question too, this is rolling back the introduction of these helpers that happened some time during 0.10 or 0.11 iirc and lead to core-util-is. The inconsistency, or at least the lack of a guiding principle bothers me a bit. |
I personally never liked the util.is*() functions, they're inefficient and unidiomatic. I won't be sad to see them go. |
I don't care for the helpers that compare to a constant/literal ( |
I did a test a few days ago where I replaced all instances of the util.is* helpers with the inline checks and performance-wise the gain was only a few percent difference here and there in the benchmarks. I would've guessed that v8 would normally inline them, but I suppose there could be cases where functions that use the helpers get deoptimized, so inlining can't occur then? I'm not sure about an |
Doesn't inlining requires a check? Like, check that |
@mscdex I was thinking |
@vkurchatkin That's right. It looks something like |
@bnoordhuis I wonder if |
@vkurchatkin It could in theory but I don't think V8 is currently smart enough to eliminate the checks completely. Don't quote me on that though, I may be operating on outdated data. :-) |
Neither did I, so I won't be sad to see them go. |
Looks like they replaced at-build-macros for the same checks: 22c68fd |
Initially the inline checks were replaced with macros in 0330bdf and the macros were converted to the util.is* functions a couple of days later in 22c68fd. EDIT: @Fishrock123 beat me to it ;-) |
I assume we're only discussing whether core should continue to use |
Yes, I don't think there is any harm keeping the convenience methods in |
I think it should also be mentioned in the docs that they aren't in use in core and just delimit their use to |
These methods weren't even documented until 95955a1. If anyone used them before that they were asking for trouble. |
Many of the util.is*() methods used to check data types simply compare against a single value or the result of typeof. This commit replaces calls to these methods with equivalent checks. This commit does not touch calls to the more complex methods (isRegExp(), isDate(), etc.). Fixes: #607 PR-URL: #647 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Closed in 6ac8bdc |
In the last PRs (#601 #605) I observed that the contributors replaced
util.isString(data)
withtypeof data === 'string'
orutil.isFunction(callback)
withtypeof callback === 'function'
, the reason for these changes are some performance optimizations, I guess these optimizations are quite insignificant, but they are still improving the performance of the code. From my point of view it's also a code style change, so my question is: Should we allow such changes in the code style? if it's "yes" then we should replace them everywhere whereutil.isType()
is used.cc TC members @chrisdickinson @bnoordhuis
The text was updated successfully, but these errors were encountered: