[Translation] [FrameworkBundle] Translation: Optimized loading (lazy loading) of domains #2570

Closed
wants to merge 2 commits into
from

Projects

None yet
@pulzarraider

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes (tests updated)
Fixes the following tickets: -

Website can have hundreds of messages in each domain. Some domains (and their translations) are not used during different requests (for example "admin" domain and their messages will not be used on public pages, "validation" domain will not be used until validating some entities/processing forms). This PR changes the way how messages are cached. Instead of storing all domains in one file (catalogue.en.php), domains are saved separately (/en/messages.php, /en/validators.php, etc.) and they are processing and loaded into memory only when they are required (to translate some text). This will optimize memory usage.

@fabpot fabpot and 1 other commented on an outdated diff Nov 23, 2011
...y/Component/Translation/MessageCatalogueInterface.php
@@ -41,6 +41,16 @@ interface MessageCatalogueInterface
function getDomains();
/**
+ * Checks if catalogue has a given domain.
+ *
+ * @param string $domain
+ *
+ * @return Boolean
+ *
+ */
+ public function hasDomain($domain);
@fabpot
fabpot Nov 23, 2011

We cannot add this method to this interface as it is marked with an @api tag.

@Tobion Tobion and 1 other commented on an outdated diff Jan 3, 2012
...ony/Bundle/FrameworkBundle/Translation/Translator.php
}
- $cache = new ConfigCache($this->options['cache_dir'].'/catalogue.'.$locale.'.php', $this->options['debug']);
+ $s = 'test';
@stof
Symfony member

@pulzarraider is this PR still valid ? If yes, please rebase your branch. It conflicts with master because of the move of the tests. If no, please close it

@pulzarraider

@stof Yes, it's valid. I will update it in the next few days.

pulzarraider added some commits Nov 5, 2011
@pulzarraider pulzarraider Translation domain loading memory optimalisation
Fixing CS

Fixing CS

Minor optimalisation

updated unit tests for new dumpers

resolve conflict with @api tags

fix CS

Translation domain loading memory optimalisation

removed unused variable

fixed conflict
bb99755
@pulzarraider pulzarraider CS fix fb137f2
@pulzarraider

@stof Rebase done, conflicts fixed.

@Koc

@stof / @fabpot , please, merge this PR

@stof
Symfony member

@Koc only @fabpot merges pull requests. Other core devs are only allowed to review them (even if github would let us push the button to merge them as there is no difference between the write access to the repo and the right to manage the issue tracker and to get notifications)

@sstok

Any new on this?

@stof
Symfony member

@fabpot should this PR be updated to be merged into 2.2 or do you think it should be rejected and closed ?

@litek

I've been using the Translation component separately with Silex, so no integrated caching at all.

My solution was to create a CachedLoader wrapper. I'm not familiar with the inner workings of Symfony, but maybe that could work here as well? It would definitely be an improvement to the standalone translation component at least.

@fabpot
Symfony member

I'm not convinced that this has a real performance impact. It would help if we had some simple benchmarks.

@pulzarraider

@fabpot The performance and memory consumption will depend on the number of translations in those domains, that are not used in a request. If the number of translations is small, it's OK to let them together in one file, because effect on performance is negligible and searching+loading+compiling+executing file costs something, too. But it will change if there exist hundreds or thousands of translations in different domains.

For example, I find completely unnecessary to automatically load translations of admin domain and store them in memory because I know that they won't be used in frontend request (public webpage). They will be used only in backend request (admin section). It's waste of resources.

Maybe we can make compromise solution and let small domains to be cached together in one file (to avoid existence of many small files in cache) and bigger domains store in cache separately (each domain in one file). This will not help webpage with many translations wrapped into a lot of domains, but I think that such cases are not frequent.

Anyway, I will update this PR for latest Symfony version and create some benchmarks in the next recent days with different number of translations to be sure my PR will not slow down the framework.

@Koc

@pulzarraider Can you continue work on the PR, please?

@pulzarraider

@Koc I am a bit busy atm, but I will continue working on this PR.

@wouterj
Symfony member
@jakzal
Symfony member

one more ping @pulzarraider ;)

@stof
Symfony member

ping again @pulzarraider

@pulzarraider

I will continue working on this PR next week.

@Tobion Tobion referenced this pull request Feb 13, 2015
Open

Translator performance #13676

@rvanlaak

A configurable threshold for merging smaller domains together would be great.

@aitboudad aitboudad referenced this pull request Mar 26, 2015
Closed

[2.7][Translation] added message cache. #13986

2 of 2 tasks complete
@nicolas-grekas

@aitboudad what do you think of this one?

@nicolas-grekas

OK you're on it, I just read the linked PR :)

@fabpot
Symfony member

Closing

@fabpot fabpot closed this Jan 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment