3 ms·
>Some V8 people here ? how can a JS re-implementation be faster than the native implementation of a function ? They say some in their readme. Because the nativ
by coldtea 12y ago
>Some V8 people here ? how can a JS re-implementation be faster than the native implementation of a function ?
They say some in their readme. Because the native versions have some extra baggage (sparse array checks, etc).
But to answer in general:
1) JS functions also get compiled to native code for often used code paths. That's what the JIT does after all.
2) A JS function might use a better algorithm compared to a native function.
3) Native is not some magic spell that is always speedier than non-native. Native code can also be slow if it carries too much baggage.
- kosinus 12y ago'Native' in V8 also does not always mean 'implemented in C++'. The readme mentions `Array#forEach`. This is the V8 implementation: https://code.google.com/p/v8/source/browse/trunk/src/array.js?r=21951#1147 https://code.google.com/p/v8/source/browse/trunk/src/array.j...