Closed Bug 1405123 Opened 7 years ago Closed 7 years ago

Only create the outer wrapper object in JSON.stringify when necessary

Categories

(Core :: JavaScript: Standard Library, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla58
Tracking Status
firefox58 --- fixed

People

(Reporter: anba, Assigned: anba)

Details

Attachments

(1 file)

When JSON.stringify is called with an object which contains only a few properties, the overhead of creating the initial wrapper object is noticeable.
Attached patch bug1405123.patchSplinter Review
This gives a performance improvement when the to be stringified object has only a few properties. For example this µ-benchmark improves from 1.5s to 1.1s:

    var o = Array(10).fill("hello");
    var t = dateNow();
    for (var i = 0; i < 1000000; ++i) {
        JSON.stringify(o);
    }
    print(dateNow() - t);
Attachment #8914670 - Flags: review?(jdemooij)
Comment on attachment 8914670 [details] [diff] [review]
bug1405123.patch

Review of attachment 8914670 [details] [diff] [review]:
-----------------------------------------------------------------

This is really great, thanks.
Attachment #8914670 - Flags: review?(jdemooij) → review+
Pushed by ryanvm@gmail.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/67b836888700
Only create the initial holder when JSON.stringify was called with a replacer function. r=jandem
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/67b836888700
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla58
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: