Closed Bug 1362225 Opened 3 years ago Closed 3 years ago

Speed up localized message generation

Categories

(WebExtensions :: General, enhancement)

enhancement
Not set

Tracking

(firefox55 fixed)

RESOLVED FIXED
mozilla55
Tracking Status
firefox55 --- fixed

People

(Reporter: kmag, Assigned: kmag)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

A lot of the overhead here is in calculating the locale list, which we can cache, and interpolating substitutions, which we can skip for messages that don't contain a "$".
Comment on attachment 8864696 [details]
Bug 1362225 - Speed up i18n.getMessage.

https://reviewboard.mozilla.org/r/136340/#review139660

::: toolkit/components/extensions/ExtensionCommon.jsm:1170
(Diff revision 1)
>        cloneScope: null,
>      };
>  
> -    options = Object.assign(defaultOptions, options);
> -
> -    let locales = new Set([this.BUILTIN, options.locale, this.defaultLocale]
> +    let locales = this.availableLocales;
> +    if (options.locale) {
> +      locales = new Set([this.BUILTIN, options.locale, this.defaultLocale]

It looks like you don't need to re-filter all the locales in this case, i.e., this could just be
```
if (this.messages.has(options.locale)) {
  locales.add(options.locale);
}
```

::: toolkit/components/extensions/ExtensionCommon.jsm:1322
(Diff revision 1)
>      return Locale.getLocale().replace(/-/g, "_");
>    },
>  };
>  
> +defineLazyGetter(LocaleData.prototype, "availableLocales", function() {
> +  return new Set([this.BUILTIN, this.selectedLocale, this.defaultLocale]

It doesn't look like selectedLocale was included before but now you've added it?
Attachment #8864696 - Flags: review?(aswan) → review+
Comment on attachment 8864696 [details]
Bug 1362225 - Speed up i18n.getMessage.

https://reviewboard.mozilla.org/r/136340/#review139660

> It looks like you don't need to re-filter all the locales in this case, i.e., this could just be
> ```
> if (this.messages.has(options.locale)) {
>   locales.add(options.locale);
> }
> ```

That would change the ordering, and we'd still need to re-filter. Anyway, this doesn't matter all that much, since it's only used at installation time.

> It doesn't look like selectedLocale was included before but now you've added it?

It was the default value for options.locale. This is only used when no options.locale value is provided.
https://hg.mozilla.org/mozilla-central/rev/65f5ee1f5db8
Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla55
Blocks: webext-perf
Product: Toolkit → WebExtensions
You need to log in before you can comment on or make changes to this bug.