use instanceof operator instead of class comparison optimization#2804
Conversation
|
I wonder if the code in the linked jsperf-snippet is actually fair and well formed. There the functions are defined too close to the test code itself plus there're only 3 functions. So technically, certain JS engine can just track all this right at the first iteration and then simply move But I'm not really |
|
Of course, the actual performance improvement depends on how often you call the modified code and what is the input, but the real reason why instanceof performs better on for example V8 is because the engine disables optimizations for toString and Object accesses. |
|
This makes sense to me.. I would merge. |
OK. Then the only question is: if we add |
|
I was going to suggest that.. but wanted to research what that effects. If its super old chrome only, lets remove it. |
|
As far as I understand the issue applies to |
|
I found something like this in several sources: http://javascript.info/tutorial/instanceof |
And this just can't ever happen inside the parser. Any |
use instanceof operator instead of class comparison optimization
|
And as usual... Thanks! :) |
It is significantly faster to use instanceof operator for type checking instead of class comparison (jsperf test:http://jsperf.com/functiontype ). The optimization is to put instanceof check at first place.