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

Performance problems of get method #224

Closed
dvlin-dev opened this issue Sep 1, 2023 · 2 comments
Closed

Performance problems of get method #224

dvlin-dev opened this issue Sep 1, 2023 · 2 comments

Comments

@dvlin-dev
Copy link
Contributor

dvlin-dev commented Sep 1, 2023

packages/react-intl-universal/src/ReactIntlUniversal.js

try {
      const msgFormatter = new IntlMessageFormat(msg, currentLocale, formats);
      return msgFormatter.format(variables);
    } catch (err) {
      this.options.warningHandler(
        `react-intl-universal format message failed for key='${key}'.`,
        err.message
      );
      return msg;
    }

No matter whether the get method passes variables or not, it will always take the IntlMessageFormat method. I don't think this is necessary. If there is no variables parameter, it can return msg directly, IntlMessageFormat will cause additional performance consumption.

If you don't pass variables, I think you can return msg directly, for example:

if (variables) {
      ...
+   } else {
+      return msg;
   }

    try {
      const msgFormatter = new IntlMessageFormat(msg, currentLocale, formats);
      return msgFormatter.format(variables);
    } catch (err) {
      this.options.warningHandler(
        `react-intl-universal format message failed for key='${key}'.`,
        err.message
      );
      return msg;
    }
@dvlin-dev
Copy link
Contributor Author

In the actual project has encountered serious performance problems, currently using patch-package to hit patch to solve, It would be great if we could merge pr.

@cwtuan
Copy link
Collaborator

cwtuan commented Sep 15, 2023

fixed in [email protected]

@cwtuan cwtuan closed this as completed Sep 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants