Improve performance of useTranslations
#294
Labels
contributions welcome
Good for people looking to contribute
enhancement
New feature or request
unconfirmed
Needs triage.
We currently have caching in place that helps with re-renders, but we could speed up the initial render by early returning for plain messages, without invoking the parser.
Detecting a plain string could either be based on if there are no values, but global values will likely defeat this strategy. A more worthwhile approach might be to quickly check the message for markers like
{
and<
. If these characters are not found, we can early return the plain string (like@formatjs/intl
).Apart from this, we could improve the parsing of messages by using a shared cache among component instances. I think if you currently render a component 100 times that uses the same messages, we'd compile the message 100 times, since we only store the compilation result in a ref. This needs to be validated and potentially changed to use a shared cache among all instances. Clearing the cache needs some thought here though. We could use the provider, but maybe we can use something that integrates with RSC.
Also check if there are other places to apply caching, e.g.
Intl.Locale
, but also constructors for number / date formats; related: #215We should also bump the message parser dependency (it has a new name on npm now).
The text was updated successfully, but these errors were encountered: