Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of useTranslations #294

Closed
amannn opened this issue May 15, 2023 · 0 comments · Fixed by #475
Closed

Improve performance of useTranslations #294

amannn opened this issue May 15, 2023 · 0 comments · Fixed by #475
Labels
contributions welcome Good for people looking to contribute enhancement New feature or request unconfirmed Needs triage.

Comments

@amannn
Copy link
Owner

amannn commented May 15, 2023

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: #215

We should also bump the message parser dependency (it has a new name on npm now).

@amannn amannn added enhancement New feature or request unconfirmed Needs triage. and removed unconfirmed Needs triage. labels May 15, 2023
@amannn amannn added contributions welcome Good for people looking to contribute and removed good first issue labels Jul 10, 2023
amannn added a commit that referenced this issue Aug 23, 2023
…e creation of message format instances if possible and introducing a cross-component message format cache (#475)

Fixes #294
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributions welcome Good for people looking to contribute enhancement New feature or request unconfirmed Needs triage.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant