-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Some ideas to improve performance of the Translator component #13948
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
Comments
great thoughts so I'll work on it :) |
Are you sure that just adding the loaders/dumpers/resources is a problem in itself? At least when it comes to memory usage, I'd guess that the registration alone does not (much) harm. However, once you need a single message from a single domain, the entire catalogue for that locale (comprising all message domains) will be loaded – and possibly the catalogues for all fallback domains as well. |
#14265 might be interesting. |
As @mpdude say previously adding the loaders/dumpers/resources or even limiting loaded resources In 2.7 we made many improvement I'd prefer to list them here: |
The tricky part probably is getting realistic scenarios that we can evaluate the optimizations against. I mean, for every change or tweak there will be setups where the change brings a big improvement, does not significantly change things or is even detrimental. Possibly influential factors are:
How can we figure out realistic numbers and come up with a "reference" dataset that we agree on for optimizations? |
Hi, I come back to you after having profiled, with BlackFire, a very huge app. This app uses 2.6 , and the Translator service is pointed as beeing very slow, for every request. The addResource() method is called 2100 times, and this one calls for preg_match(), 2100 times so. I saw that 2.7 tried to fix that. Isnt there a way to simply remove the load of the catalogues, knowing that anyway, in prod, every translation/catalogue is cached (and if not, you then failed your deploy) ? |
@aitboudad thx |
Guys, I think that this is a must. In our application, we have a lot of translation files, with thousands of strings to translate, but we support the translation of the application in just a few languages for now. I created a compiler pass that removes the resources for locales that we don't support and we got a 3 minute decrease in our build times. I think that a lot of applications can benefit with something like this. |
I'm closing this issue because it's too generic and proposes no specific solutions. @aitboudad is taking good care of this and a lot of improvements have already been implemented. |
The problem
Recently some people have raised concerns about Translator component performance (see #13676 for example). I was inspecting the dumped container for production environment to get more information about this component and I saw the following problems:
1. All translation loaders and dumpers are instantiated and loaded, no matter which ones you use:
Same thing happens with the translation dumpers:
2. All resources for all locales are loaded, no matter which ones you use:
The solution
1. We could solve this problem with a technique similar to the templating engines selector:
In the case of
translator
:To maintain backwards compatibility, these options could be
null
by default, meaning that all loaders/dumpers should be loaded.2. We could solve this problem defining a new
active_locales
option to explicitly define the list of locales which will be used in the application:Again, to maintain backwards compatibility, this new option would default to
null
to load all resources for all locales.The benchmark
In my tests, I modified the generated container commenting/removing the lines that instantiate all the unused loaders/dumpers and I also removed all the translation resources files except the ones for the active locale. A quick before/after comparison made with Blackfire gave me around 10% performance increase in CPU time, 2.64% memory consumption reduction and about 600 less PHP function calls.
The text was updated successfully, but these errors were encountered: