[Translator] Many performance improvements on the cache warming#2206
Merged
Kocal merged 7 commits intosymfony:2.xfrom Sep 26, 2024
Merged
[Translator] Many performance improvements on the cache warming#2206Kocal merged 7 commits intosymfony:2.xfrom
Kocal merged 7 commits intosymfony:2.xfrom
Conversation
…MessageParser#offset()`
… `IntlMessageParser#generateConstantName()`
… to `->slice($offset, 1)`
…revent unnecessary computations
969c6cf to
1309032
Compare
smnandre
reviewed
Sep 26, 2024
smnandre
reviewed
Sep 26, 2024
7b38d80 to
4f3c9e4
Compare
4f3c9e4 to
02e1eb3
Compare
kbond
approved these changes
Sep 26, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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):

The vast majority of improvements come from better use of the Symfony String component.
Blackfire profiles:
s()instancess()->slice()$this->message->length()as it will always return the same lengthAlso, since the Translator component is still experimental, I've marked some classes as final and internal, as they should only be used internally. :)