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

[Intl] Move NumberFormat to LocalizedNumberFormatter

Speed up Intl.PluralRules constructor x3.4

$python -u tools/run_perf.py --binary-override-path  \
   out/x64.release/d8 --filter "JSTests/Intl" \
   test/js-perf-test/JSTests5.json

Score for NewIntlPluralRules
BEFORE  550  581  576
AFTER  1856 1978 1996


Bug: v8:9300
Change-Id: I76b4290aa433b1049e3ee770d391b86e468e967d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1630134
Commit-Queue: Frank Tang <ftang@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61924}
parent b179dd83
...@@ -2167,7 +2167,7 @@ void JSPluralRules::JSPluralRulesPrint(std::ostream& os) { // NOLINT ...@@ -2167,7 +2167,7 @@ void JSPluralRules::JSPluralRulesPrint(std::ostream& os) { // NOLINT
os << "\n - locale: " << Brief(locale()); os << "\n - locale: " << Brief(locale());
os << "\n - type: " << TypeAsString(); os << "\n - type: " << TypeAsString();
os << "\n - icu plural rules: " << Brief(icu_plural_rules()); os << "\n - icu plural rules: " << Brief(icu_plural_rules());
os << "\n - icu decimal format: " << Brief(icu_decimal_format()); os << "\n - icu_number_formatter: " << Brief(icu_number_formatter());
JSObjectPrintBody(os, *this); JSObjectPrintBody(os, *this);
} }
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "unicode/formattedvalue.h" #include "unicode/formattedvalue.h"
#include "unicode/locid.h" #include "unicode/locid.h"
#include "unicode/normalizer2.h" #include "unicode/normalizer2.h"
#include "unicode/numberformatter.h"
#include "unicode/numfmt.h" #include "unicode/numfmt.h"
#include "unicode/numsys.h" #include "unicode/numsys.h"
#include "unicode/timezone.h" #include "unicode/timezone.h"
......
...@@ -37,8 +37,9 @@ extern class JSNumberFormat extends JSObject { ...@@ -37,8 +37,9 @@ extern class JSNumberFormat extends JSObject {
extern class JSPluralRules extends JSObject { extern class JSPluralRules extends JSObject {
locale: String; locale: String;
flags: Smi; flags: Smi;
icu_plural_rules: Foreign; // Managed<icu::PluralRules> icu_plural_rules: Foreign; // Managed<icu::PluralRules>
icu_decimal_format: Foreign; // Managed<icu::DecimalFormat> icu_number_formatter:
Foreign; // Managed<icu::number::LocalizedNumberFormatter>
} }
extern class JSRelativeTimeFormat extends JSObject { extern class JSRelativeTimeFormat extends JSObject {
......
...@@ -485,6 +485,8 @@ Handle<String> SignDisplayString(Isolate* isolate, ...@@ -485,6 +485,8 @@ Handle<String> SignDisplayString(Isolate* isolate,
return ReadOnlyRoots(isolate).auto_string_handle(); return ReadOnlyRoots(isolate).auto_string_handle();
} }
} // anonymous namespace
// Return the minimum integer digits by counting the number of '0' after // Return the minimum integer digits by counting the number of '0' after
// "integer-width/+" in the skeleton. // "integer-width/+" in the skeleton.
// Ex: Return 15 for skeleton as // Ex: Return 15 for skeleton as
...@@ -492,7 +494,8 @@ Handle<String> SignDisplayString(Isolate* isolate, ...@@ -492,7 +494,8 @@ Handle<String> SignDisplayString(Isolate* isolate,
// 1 // 1
// 123456789012345 // 123456789012345
// Return default value as 1 if there are no "integer-width/+". // Return default value as 1 if there are no "integer-width/+".
int32_t MinimumIntegerDigitsFromSkeleton(const icu::UnicodeString& skeleton) { int32_t JSNumberFormat::MinimumIntegerDigitsFromSkeleton(
const icu::UnicodeString& skeleton) {
// count the number of 0 after "integer-width/+" // count the number of 0 after "integer-width/+"
icu::UnicodeString search("integer-width/+"); icu::UnicodeString search("integer-width/+");
int32_t index = skeleton.indexOf(search); int32_t index = skeleton.indexOf(search);
...@@ -515,8 +518,8 @@ int32_t MinimumIntegerDigitsFromSkeleton(const icu::UnicodeString& skeleton) { ...@@ -515,8 +518,8 @@ int32_t MinimumIntegerDigitsFromSkeleton(const icu::UnicodeString& skeleton) {
// 123 // 123
// 4567 // 4567
// Set The minimum as 3 and maximum as 7. // Set The minimum as 3 and maximum as 7.
bool FractionDigitsFromSkeleton(const icu::UnicodeString& skeleton, bool JSNumberFormat::FractionDigitsFromSkeleton(
int32_t* minimum, int32_t* maximum) { const icu::UnicodeString& skeleton, int32_t* minimum, int32_t* maximum) {
icu::UnicodeString search("."); icu::UnicodeString search(".");
int32_t index = skeleton.indexOf(search); int32_t index = skeleton.indexOf(search);
if (index < 0) return false; if (index < 0) return false;
...@@ -542,8 +545,8 @@ bool FractionDigitsFromSkeleton(const icu::UnicodeString& skeleton, ...@@ -542,8 +545,8 @@ bool FractionDigitsFromSkeleton(const icu::UnicodeString& skeleton,
// 12345 // 12345
// 6789012 // 6789012
// Set The minimum as 5 and maximum as 12. // Set The minimum as 5 and maximum as 12.
bool SignificantDigitsFromSkeleton(const icu::UnicodeString& skeleton, bool JSNumberFormat::SignificantDigitsFromSkeleton(
int32_t* minimum, int32_t* maximum) { const icu::UnicodeString& skeleton, int32_t* minimum, int32_t* maximum) {
icu::UnicodeString search("@"); icu::UnicodeString search("@");
int32_t index = skeleton.indexOf(search); int32_t index = skeleton.indexOf(search);
if (index < 0) return false; if (index < 0) return false;
...@@ -561,6 +564,8 @@ bool SignificantDigitsFromSkeleton(const icu::UnicodeString& skeleton, ...@@ -561,6 +564,8 @@ bool SignificantDigitsFromSkeleton(const icu::UnicodeString& skeleton,
return true; return true;
} }
namespace {
// Ex: percent .### rounding-mode-half-up // Ex: percent .### rounding-mode-half-up
// Special case for "percent" // Special case for "percent"
// Ex: "measure-unit/length-kilometer per-measure-unit/duration-hour .### // Ex: "measure-unit/length-kilometer per-measure-unit/duration-hour .###
...@@ -642,9 +647,6 @@ Handle<JSObject> JSNumberFormat::ResolvedOptions( ...@@ -642,9 +647,6 @@ Handle<JSObject> JSNumberFormat::ResolvedOptions(
icu::UnicodeString skeleton = icu_number_formatter->toSkeleton(status); icu::UnicodeString skeleton = icu_number_formatter->toSkeleton(status);
CHECK(U_SUCCESS(status)); CHECK(U_SUCCESS(status));
std::string s_str;
s_str = skeleton.toUTF8String<std::string>(s_str);
// 4. Let options be ! ObjectCreate(%ObjectPrototype%). // 4. Let options be ! ObjectCreate(%ObjectPrototype%).
Handle<JSObject> options = factory->NewJSObject(isolate->object_function()); Handle<JSObject> options = factory->NewJSObject(isolate->object_function());
......
...@@ -17,14 +17,15 @@ ...@@ -17,14 +17,15 @@
#include "src/objects/intl-objects.h" #include "src/objects/intl-objects.h"
#include "src/objects/managed.h" #include "src/objects/managed.h"
#include "src/objects/objects.h" #include "src/objects/objects.h"
#include "unicode/numberformatter.h"
// Has to be the last include (doesn't have include guards): // Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h" #include "src/objects/object-macros.h"
namespace U_ICU_NAMESPACE { namespace U_ICU_NAMESPACE {
class NumberFormat;
class UnicodeString; class UnicodeString;
namespace number {
class LocalizedNumberFormatter;
} // namespace number
} // namespace U_ICU_NAMESPACE } // namespace U_ICU_NAMESPACE
namespace v8 { namespace v8 {
...@@ -56,6 +57,13 @@ class JSNumberFormat : public JSObject { ...@@ -56,6 +57,13 @@ class JSNumberFormat : public JSObject {
V8_EXPORT_PRIVATE static const std::set<std::string>& GetAvailableLocales(); V8_EXPORT_PRIVATE static const std::set<std::string>& GetAvailableLocales();
static int32_t MinimumIntegerDigitsFromSkeleton(
const icu::UnicodeString& skeleton);
static bool FractionDigitsFromSkeleton(const icu::UnicodeString& skeleton,
int32_t* minimum, int32_t* maximum);
static bool SignificantDigitsFromSkeleton(const icu::UnicodeString& skeleton,
int32_t* minimum, int32_t* maximum);
DECL_CAST(JSNumberFormat) DECL_CAST(JSNumberFormat)
DECL_PRINTER(JSNumberFormat) DECL_PRINTER(JSNumberFormat)
DECL_VERIFIER(JSNumberFormat) DECL_VERIFIER(JSNumberFormat)
......
...@@ -25,8 +25,9 @@ ACCESSORS(JSPluralRules, locale, String, kLocaleOffset) ...@@ -25,8 +25,9 @@ ACCESSORS(JSPluralRules, locale, String, kLocaleOffset)
SMI_ACCESSORS(JSPluralRules, flags, kFlagsOffset) SMI_ACCESSORS(JSPluralRules, flags, kFlagsOffset)
ACCESSORS(JSPluralRules, icu_plural_rules, Managed<icu::PluralRules>, ACCESSORS(JSPluralRules, icu_plural_rules, Managed<icu::PluralRules>,
kIcuPluralRulesOffset) kIcuPluralRulesOffset)
ACCESSORS(JSPluralRules, icu_decimal_format, Managed<icu::DecimalFormat>, ACCESSORS(JSPluralRules, icu_number_formatter,
kIcuDecimalFormatOffset) Managed<icu::number::LocalizedNumberFormatter>,
kIcuNumberFormatterOffset)
inline void JSPluralRules::set_type(Type type) { inline void JSPluralRules::set_type(Type type) {
DCHECK_LT(type, Type::COUNT); DCHECK_LT(type, Type::COUNT);
......
This diff is collapsed.
...@@ -22,8 +22,10 @@ ...@@ -22,8 +22,10 @@
#include "src/objects/object-macros.h" #include "src/objects/object-macros.h"
namespace U_ICU_NAMESPACE { namespace U_ICU_NAMESPACE {
class DecimalFormat;
class PluralRules; class PluralRules;
namespace number {
class LocalizedNumberFormatter;
} // namespace number
} // namespace U_ICU_NAMESPACE } // namespace U_ICU_NAMESPACE
namespace v8 { namespace v8 {
...@@ -76,7 +78,8 @@ class JSPluralRules : public JSObject { ...@@ -76,7 +78,8 @@ class JSPluralRules : public JSObject {
DECL_ACCESSORS(locale, String) DECL_ACCESSORS(locale, String)
DECL_INT_ACCESSORS(flags) DECL_INT_ACCESSORS(flags)
DECL_ACCESSORS(icu_plural_rules, Managed<icu::PluralRules>) DECL_ACCESSORS(icu_plural_rules, Managed<icu::PluralRules>)
DECL_ACCESSORS(icu_decimal_format, Managed<icu::DecimalFormat>) DECL_ACCESSORS(icu_number_formatter,
Managed<icu::number::LocalizedNumberFormatter>)
OBJECT_CONSTRUCTORS(JSPluralRules, JSObject); OBJECT_CONSTRUCTORS(JSPluralRules, JSObject);
}; };
......
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