Closed Bug 1517235 Opened 7 years ago Closed 7 years ago

Add fast path for number inputs to parseFloat

Categories

(Core :: JavaScript: Standard Library, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla66
Tracking Status
firefox66 --- fixed

People

(Reporter: anba, Assigned: anba)

References

Details

Attachments

(1 file)

Similar to the existing fast path for numbers values in parseInt we should also fast path numbers in parseFloat. The fps counter in the benchmark from bug 1515620 calls the following function to determine if a value is a number: --- function isNumber(n) { return !isNaN(parseFloat(n)) && isFinite(n); } --- where |n| is always a number value. That means for us we're first stringifying the number in |num_parseFloat| and immediately after that we're calling |js_strtod| to convert the string back to a number. Especially the string conversion is expensive, because we're allocation lots of strings which leads to more work for the GC. Without a number fast path in |num_parseFloat|, the |averageFpsFromTimes| function from the benchmark tool spends about 14.25% of the complete runtime. With the fast path it's only at 6.25% (*). (*) The fps counter function is also creating lots of array objects in its |numbers| function, so we spend quite some time in |js::NativeObject::setOrExtendDenseElements| when called from |js::jit::ArrayPushDense|.
Attached patch bug1517235.patch — — Splinter Review
We can directly return the input value if it's a number - except for negative zero, which must be returned as positive zero. (*) While there I've also added a fast path for strings which contain an index-value. (*) This case is already covered in <https://searchfox.org/mozilla-central/source/js/src/tests/test262/built-ins/parseFloat/S15.1.2.3_A1_T2.js>, so I didn't have to write a new test case. \o/
Attachment #9033955 - Flags: review?(jorendorff)
Comment on attachment 9033955 [details] [diff] [review] bug1517235.patch Review of attachment 9033955 [details] [diff] [review]: ----------------------------------------------------------------- Very nice!
Attachment #9033955 - Flags: review?(jorendorff) → review+
Pushed by dluca@mozilla.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/58633320257f Add fast path for number inputs to parseFloat. r=jorendorff
Keywords: checkin-needed
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla66
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: