-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Translator] fix performance issue in MessageCatalogue and catalogue operations #35125
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
Merged
Conversation
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
Can you try replacing the call to array_replace() by a foreach over $messages (and keeping set() as-is). |
Did that, that leads to same performance impovement. foreach over $messages is as good as what i did in terms of speed. Should I update pull request? |
Yes please, because that would improve the performance of add() too, and would make the patch shorter. |
Done |
nicolas-grekas
approved these changes
Dec 28, 2019
Thank you @ArtemBrovko. |
nicolas-grekas
added a commit
that referenced
this pull request
Dec 31, 2019
… catalogue operations (ArtemBrovko) This PR was merged into the 3.4 branch. Discussion ---------- [Translator] fix performance issue in MessageCatalogue and catalogue operations | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - In our project we use lots of catalogue operations during importing of translations to our system and we ran into performance issue. Code profiler showed lots or `array_replace` calls in [MessageCatalogue::add](https://github.com/symfony/symfony/blob/3.4/src/Symfony/Component/Translation/MessageCatalogue.php#L128) method. This method is actually called by [MessageCatalogue::set](https://github.com/symfony/symfony/blob/3.4/src/Symfony/Component/Translation/MessageCatalogue.php#L70), which is quite an overkill, because `MessageCatalogue::set` is meant to set only one translation at a time. Method was reworked. `MergeOperation` and `TargetOperation` was reworked as well to use this improved `MessageCatalogue::set` method instead of constructing array with only one translation and passing it to `MessageCatalogue::add` method. Table shows execution time before and after | | Time in seconds (avg. of 10 executions) ----------- | ------ Before | 50 After | 8 Looks like 4.* and 5.* versions can also be improved by the same changes. <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/roadmap): - Always add tests and ensure they pass. - Never break backward compatibility (see https://symfony.com/bc). - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.) - Features and deprecations must be submitted against branch master. --> Commits ------- 5179af4 [Translator] Performance improvement in MessageCatalogue and catalogue operations.
This was referenced Jan 21, 2020
Merged
Merged
Merged
Merged
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.
In our project we use lots of catalogue operations during importing of translations to our system and we ran into performance issue. Code profiler showed lots or
array_replace
calls in MessageCatalogue::add method. This method is actually called by MessageCatalogue::set, which is quite an overkill, becauseMessageCatalogue::set
is meant to set only one translation at a time. Method was reworked.MergeOperation
andTargetOperation
was reworked as well to use this improvedMessageCatalogue::set
method instead of constructing array with only one translation and passing it toMessageCatalogue::add
method.Table shows execution time before and after
Looks like 4.* and 5.* versions can also be improved by the same changes.