Skip to content
New issue

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

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

Already on GitHub? # to your account

[Translator] Many performance improvements on the cache warming #2206

Merged
merged 7 commits into from
Sep 26, 2024

Conversation

Kocal
Copy link
Collaborator

@Kocal Kocal commented Sep 25, 2024

Q A
Bug fix? no
New feature? no
Issues Fix #...
License MIT

The Symfony UX Translator cache warmer can be an long task, especially if your app has a lot of translations.

I was able to identify some bottlenecks and fix them, with a dedicated commit for each of them.

My test application have ~25k translation keys (3.119 keys * 8 locales). Of course that's a lot, but I believe some people needs to dump all their translations (e.g. if they build an SPA on Symfony). For "more classic" applications, it is recommended to use dedicated domains for translations JS-side.

Anyway, in my application, I was able to reduce the Translator cache warming from 2m11s (higher than the reality, because of Blackfire profiling) to 41s (higher than the reality, because of Blackfire profiling):
image

The vast majority of improvements come from better use of the Symfony String component.

Blackfire profiles:

  1. Initial
  2. Re-using s() instances
  3. Removing useless s()->slice()
  4. Caching $this->message->length() as it will always return the same length
  5. Before/After: ~63% 🚀

Also, since the Translator component is still experimental, I've marked some classes as final and internal, as they should only be used internally. :)

@carsonbot carsonbot added the Status: Needs Review Needs to be reviewed label Sep 25, 2024
Copy link
Collaborator

@smnandre smnandre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trusting you here :)

@Kocal Kocal force-pushed the imp-translations-cache-warmer-perf branch 2 times, most recently from 7b38d80 to 4f3c9e4 Compare September 26, 2024 05:37
@Kocal Kocal force-pushed the imp-translations-cache-warmer-perf branch from 4f3c9e4 to 02e1eb3 Compare September 26, 2024 05:39
@carsonbot carsonbot added Status: Reviewed Has been reviewed by a maintainer and removed Status: Needs Review Needs to be reviewed labels Sep 26, 2024
Copy link
Collaborator

@smnandre smnandre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤝

@Kocal Kocal merged commit 6330ad1 into symfony:2.x Sep 26, 2024
59 checks passed
@Kocal Kocal deleted the imp-translations-cache-warmer-perf branch September 26, 2024 08:48
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Performance Status: Reviewed Has been reviewed by a maintainer Translator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants