Eliminate a useless copy under FunctionToString

RESOLVED FIXED in Firefox 56

Status

()

defect
RESOLVED FIXED
2 years ago
2 years ago

People

(Reporter: jandem, Assigned: jandem)

Tracking

unspecified
mozilla56
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(firefox56 fixed)

Details

Attachments

(1 attachment)

Assignee

Description

2 years ago
Posted 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+

Comment 2

2 years ago
Pushed by jandemooij@gmail.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/f48357605b40
Eliminate unnecessary string allocation + copy under FunctionToString. r=luke

Comment 3

2 years ago
bugherder
https://hg.mozilla.org/mozilla-central/rev/f48357605b40
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla56
You need to log in before you can comment on or make changes to this bug.