It's never completely free to use const, since we do a runtime call to
initialize the variable, but in the global scope, that should only happen
once.
Global code, properly written, won't get optimized, and the global object's
properties aren't treated like normal scoped variables, so for performance
this
is the only difference. It won't affect optimization of the functions that
can
access the variable.
http://codereview.chromium.org/7830036/diff/1/src/v8natives.js
File src/v8natives.js (left):
http://codereview.chromium.org/7830036/diff/1/src/v8natives.js#oldcode43
src/v8natives.js:43:
We shouldn't use "const" at all.
The primary reason is that const isn't well-specified, and we might be
forced to change its semantics to match Safari. For that reason, we
shouldn't be using it for security (which is the reason it's used here -
someone getting hold of the builtins object shouldn't be able to change
the behavior of internal builtin functions.
It won't affect performance here, since global variables aren't as bad
as local const variables.
It will be changed, at some point, to not using const, but not for
performance reasons.
http://codereview.chromium.org/7830036/diff/1/src/v8natives.js
File src/v8natives.js (right):
http://codereview.chromium.org/7830036/diff/1/src/v8natives.js#newcode96
src/v8natives.js:96: return !NUMBER_IS_NAN(number) && number !== (1 / 0)
&& number !== (-1 / 0);
That depends a lot on the test.
My, admittedly very artificial, benchmark gets a 20% performance
reduction when I remove the %_IsSmi from the macro.
We can try changing the NUMBER_IS_NAN and NUMBER_IS_FINITE macros and
give it a run at the some benchmarks, but I won't do that in this CL.
http://codereview.chromium.org/7830036/
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev