Closed Bug 1549578 Opened 6 years ago Closed 5 years ago

Cache most recently used UDateTimePatternGenerator

Categories

(Core :: JavaScript: Internationalization API, enhancement, P1)

enhancement

Tracking

()

RESOLVED FIXED
mozilla69
Tracking Status
firefox68 --- wontfix
firefox69 --- fixed

People

(Reporter: anba, Assigned: anba)

Details

Attachments

(1 file)

Per https://v8.dev/blog/intl (currently not reachable, alternative source: https://github.com/v8/v8.dev/blob/master/src/blog/intl.md), V8 improved the time needed to allocate of Intl objects (V8 benchmark: https://github.com/v8/v8/blob/master/test/js-perf-test/Intl/constructor.js). We're now slower for the Intl.DateTimeFormat allocation benchmark, because we don't cache the UDateTimePatternGenerator, but instead always create a new one in intl_patternForSkeleton. V8 is currently caching the pattern generators for all locales, which would mean for us storing up to 750 [1] UDateTimePatternGenerator instances. But I guess for most use cases it's sufficient to only store the most recently used instance, so I'm proposing to do only that for the time being.

[1] Object.keys(getSelfHostedValue("intl_DateTimeFormat_availableLocales")()).length returns 750.

Caching the most recent UDateTimePatternGenerator instance improves the following µ-benchmark from ~570ms to ~30ms for me:

function test() {
    var t = dateNow();
    for (var i = 0; i < 1000; ++i) {
        var dtf = new Intl.DateTimeFormat();
        dtf.resolvedOptions(); // instantiate lazily computed elements
    }
    print(dateNow() - t);
}

For comparison, V8 needs ~160ms for that µ-benchmark.

With the requested tweaks to this so small, I went ahead and made them and queued this up for landing.

Priority: -- → P1
Pushed by jwalden@mit.edu: https://hg.mozilla.org/integration/autoland/rev/075075cb0b88 Cache most recently used UDateTimePatternGenerator in SharedIntlData. r=jwalden
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla69
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: