Commit a9174cf0 authored by Frank Tang's avatar Frank Tang Committed by Commit Bot

[Intl] Speedup by cache DateTimePatternGenerator

$ python -u tools/run_perf.py --binary-override-path   out/x64.release/d8 --filter "JSTests/Intl"   test/js-perf-test/JSTests.json
...
NewIntlDateTimeFormat-Intl(Score): 92.9

Compare to baseline in
https://chromium-review.googlesource.com/c/v8/v8/+/1455727

improve another x3.5

Bug: chromium:928098
Change-Id: Iab6b9e2d58231832c54bc626d01b25a3813537fa
Reviewed-on: https://chromium-review.googlesource.com/c/1457603Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59444}
parent 7e914db5
......@@ -1003,6 +1003,28 @@ std::unique_ptr<icu::SimpleDateFormat> DateTimeStylePattern(
generator);
}
class DateTimePatternGeneratorCache {
public:
// Return a clone copy that the caller have to free.
icu::DateTimePatternGenerator* CreateGenerator(const icu::Locale& locale) {
std::string key(locale.getBaseName());
base::MutexGuard guard(&mutex_);
auto it = map_.find(key);
if (it != map_.end()) {
return it->second->clone();
}
UErrorCode status = U_ZERO_ERROR;
map_[key].reset(icu::DateTimePatternGenerator::createInstance(
icu::Locale(key.c_str()), status));
CHECK(U_SUCCESS(status));
return map_[key]->clone();
}
private:
std::map<std::string, std::unique_ptr<icu::DateTimePatternGenerator>> map_;
base::Mutex mutex_;
};
} // namespace
enum FormatMatcherOption { kBestFit, kBasic };
......@@ -1093,14 +1115,14 @@ MaybeHandle<JSDateTimeFormat> JSDateTimeFormat::Initialize(
JSDateTimeFormat);
}
icu::Locale no_extension_locale(icu_locale.getBaseName());
UErrorCode status = U_ZERO_ERROR;
static base::LazyInstance<DateTimePatternGeneratorCache>::type
generator_cache = LAZY_INSTANCE_INITIALIZER;
std::unique_ptr<icu::DateTimePatternGenerator> generator(
icu::DateTimePatternGenerator::createInstance(no_extension_locale,
status));
CHECK(U_SUCCESS(status));
generator_cache.Pointer()->CreateGenerator(icu_locale));
// 15.Let hcDefault be dataLocaleData.[[hourCycle]].
UErrorCode status = U_ZERO_ERROR;
icu::UnicodeString hour_pattern = generator->getBestPattern("jjmm", status);
CHECK(U_SUCCESS(status));
Intl::HourCycle hc_default = HourCycleFromPattern(hour_pattern);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment