Skip to content

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

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

Conversation

pulzarraider
Copy link
Contributor

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.

* @return Boolean
*
*/
public function hasDomain($domain);
Copy link
Member

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, thanks.

@stof
Copy link
Member

stof commented Apr 4, 2012

@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
Copy link
Contributor Author

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

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
@pulzarraider
Copy link
Contributor Author

@stof Rebase done, conflicts fixed.

@Koc
Copy link
Contributor

Koc commented Apr 22, 2012

@stof / @fabpot , please, merge this PR

@stof
Copy link
Member

stof commented Apr 23, 2012

@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
Copy link
Contributor

sstok commented Aug 26, 2012

Any new on this?

@stof
Copy link
Member

stof commented Oct 13, 2012

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

@litek
Copy link

litek commented Nov 5, 2012

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
Copy link
Member

fabpot commented Apr 25, 2013

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

@pulzarraider
Copy link
Contributor Author

@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
Copy link
Contributor

Koc commented Jan 17, 2014

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

@pulzarraider
Copy link
Contributor Author

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

@wouterj
Copy link
Member

wouterj commented Jul 24, 2014

ping @pulzarraider

@jakzal
Copy link
Contributor

jakzal commented Dec 12, 2014

one more ping @pulzarraider ;)

@stof
Copy link
Member

stof commented Jan 18, 2015

ping again @pulzarraider

@pulzarraider
Copy link
Contributor Author

I will continue working on this PR next week.

@Tobion Tobion mentioned this pull request Feb 13, 2015
@rvanlaak
Copy link
Contributor

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

@ghost
Copy link

ghost commented May 1, 2015

ping @pulzarraider

@nicolas-grekas
Copy link
Member

@aitboudad what do you think of this one?

@nicolas-grekas
Copy link
Member

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

@fabpot
Copy link
Member

fabpot commented Jan 25, 2016

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.