Closed Bug 1377489 Opened 7 years ago Closed 7 years ago

Eliminate a useless copy under FunctionToString

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla56
Tracking Status
firefox56 --- fixed

People

(Reporter: jandem, Assigned: jandem)

References

Details

Attachments

(1 file)

Attached patch PatchSplinter Review
Noticed this while looking at bug 1377343. Right now we get the function's source code as JSString (including malloc + copying/Latin1-izing chars) then we append this string to a StringBuffer. That's just silly since we can pass a StringBuffer and append directly to that. The attached patch does this. For the micro-benchmark below I get: before: 592 ms after: 435 ms Still a lot of slowness here but it's a decent win. function test() { var s = ""; for (var i = 0; i < 1000; i++) s += "var x = 10;"; var f = Function(s); var t = new Date; for (var i = 0; i < 50000; i++) s = f.toString(); alert(new Date - t); } test();
Attachment #8882603 - Flags: review?(luke)
Comment on attachment 8882603 [details] [diff] [review] Patch Review of attachment 8882603 [details] [diff] [review]: ----------------------------------------------------------------- Good observation.
Attachment #8882603 - Flags: review?(luke) → review+
Pushed by jandemooij@gmail.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/f48357605b40 Eliminate unnecessary string allocation + copy under FunctionToString. r=luke
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla56
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: