Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Issue 7830036: Optimize isFinite and isNaN. (Closed)

Created:
9 years, 3 months ago by Lasse Reichstein
Modified:
9 years, 3 months ago
CC:
v8-dev
Visibility:
Public.

Description

Optimize isFinite and isNaN. Arithmetic on infinities and NaN is much slower than doing several exact comparisons. Committed: http://code.google.com/p/v8/source/detail?r=9134

Patch Set 1 #

Total comments: 4

Patch Set 2 : Made the change general by moving putting it in the NUMBER_IS_FINITE macro. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+478 lines, -777 lines) Patch
M samples/shell.cc View 1 1 chunk +4 lines, -2 lines 0 comments Download
M src/arm/code-stubs-arm.cc View 1 5 chunks +10 lines, -10 lines 0 comments Download
M src/array.js View 1 3 chunks +18 lines, -13 lines 0 comments Download
M src/ast.h View 1 3 chunks +57 lines, -0 lines 0 comments Download
M src/ast.cc View 1 3 chunks +24 lines, -0 lines 0 comments Download
M src/date.js View 1 2 chunks +5 lines, -6 lines 0 comments Download
M src/extensions/externalize-string-extension.cc View 1 1 chunk +2 lines, -4 lines 0 comments Download
M src/heap.h View 1 1 chunk +2 lines, -1 line 0 comments Download
M src/isolate.h View 1 3 chunks +4 lines, -0 lines 0 comments Download
M src/isolate.cc View 1 3 chunks +5 lines, -0 lines 0 comments Download
M src/json.js View 1 1 chunk +2 lines, -3 lines 0 comments Download
M src/macros.py View 1 1 chunk +1 line, -1 line 0 comments Download
M src/math.js View 1 3 chunks +6 lines, -6 lines 0 comments Download
M src/messages.js View 1 24 chunks +39 lines, -88 lines 0 comments Download
M src/mips/code-stubs-mips.cc View 1 9 chunks +56 lines, -128 lines 0 comments Download
M src/mips/constants-mips.h View 1 1 chunk +4 lines, -2 lines 0 comments Download
M src/mips/frames-mips.h View 1 1 chunk +3 lines, -0 lines 0 comments Download
M src/mips/macro-assembler-mips.h View 1 2 chunks +3 lines, -12 lines 0 comments Download
M src/mips/macro-assembler-mips.cc View 1 3 chunks +6 lines, -42 lines 0 comments Download
M src/mips/simulator-mips.cc View 1 1 chunk +1 line, -1 line 0 comments Download
M src/mksnapshot.cc View 1 2 chunks +12 lines, -0 lines 0 comments Download
M src/parser.cc View 1 3 chunks +15 lines, -20 lines 0 comments Download
M src/profile-generator.h View 1 4 chunks +2 lines, -4 lines 0 comments Download
M src/profile-generator.cc View 1 3 chunks +4 lines, -30 lines 0 comments Download
M src/regexp.js View 1 2 chunks +3 lines, -3 lines 0 comments Download
M src/runtime.h View 1 1 chunk +0 lines, -1 line 0 comments Download
M src/runtime.cc View 1 3 chunks +0 lines, -8 lines 0 comments Download
M src/scanner.h View 1 1 chunk +2 lines, -0 lines 0 comments Download
M src/scopes.h View 1 1 chunk +0 lines, -5 lines 0 comments Download
M src/scopes.cc View 1 1 chunk +0 lines, -29 lines 0 comments Download
M src/string.js View 1 2 chunks +32 lines, -28 lines 0 comments Download
M src/uri.js View 1 2 chunks +3 lines, -4 lines 0 comments Download
M src/v8natives.js View 1 14 chunks +122 lines, -145 lines 0 comments Download
M src/weakmap.js View 1 2 chunks +5 lines, -3 lines 0 comments Download
M test/cctest/test-regexp.cc View 1 1 chunk +4 lines, -5 lines 0 comments Download
D test/mjsunit/builtins.js View 1 1 chunk +0 lines, -83 lines 0 comments Download
M test/mjsunit/harmony/debug-blockscopes.js View 1 7 chunks +22 lines, -77 lines 0 comments Download
M test/mjsunit/parse-int-float.js View 1 1 chunk +0 lines, -13 lines 0 comments Download

Messages

Total messages: 5 (0 generated)
Lasse Reichstein
9 years, 3 months ago (2011-09-02 13:32:01 UTC) #1
William Hesse
LGTM.
9 years, 3 months ago (2011-09-02 13:41:34 UTC) #2
Sven Panne
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) && ...
9 years, 3 months ago (2011-09-02 16:00:14 UTC) #3
PhistucK
Can you clarify where it is fine/totally neutral for "const" to be in run time ...
9 years, 3 months ago (2011-09-02 20:24:34 UTC) #4
Lasse Reichstein
9 years, 3 months ago (2011-09-05 10:51:16 UTC) #5
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.

Powered by Google App Engine
This is Rietveld 408576698