-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Optimize framework extension tests #17399
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
$dataHash = md5(serialize($data)); | ||
|
||
if (!isset(self::$containerCache[$file][$dataHash])) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove the extra empty line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ty. :) Done.
$container = $this->createContainer($data); | ||
$container->registerExtension(new FrameworkExtension()); | ||
$this->loadFromFile($container, $file); | ||
$dataHash = md5(serialize($data)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the nitpicking: should we rename $dataHash
to $cacheKey
or $cacheId
?
@paradajozsef this is really impressive. This change keeps code readable and, according to your stats, it saves around 20 seconds in total. Thanks for this contribution and for your perfectly explained pull request. |
@javiereguiluz thank you. :) renamed |
$container = $this->createContainer($data); | ||
$container->registerExtension(new FrameworkExtension()); | ||
$this->loadFromFile($container, $file); | ||
$cacheKey = md5(serialize($data)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about taking the value of $file
into account here too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a good idea! $containerCache
became simpler. Thank you! :)
👍 Status: Reviewed |
|
||
if (!isset(self::$containerCache[$cacheKey])) { | ||
$container = $this->createContainer($data); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove this extra line?
@fabpot Yes, it should have been done so for the first time. Anyway, I changed the if statement. |
Thank you @paradajozsef. |
…radajozsef) This PR was squashed before being merged into the 2.3 branch (closes #17399). Discussion ---------- [FrameworkBundle] Optimize framework extension tests | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #17366 | License | MIT | Doc PR | - ```XmlFrameworkExtensionTest```, ```YamlFrameworkExtensionTest``` and ```PhpFrameworkExtensionTest``` are slow tests. The reason is that the [parent test](https://github.com/symfony/symfony/blob/2.3/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php#L308) creates the container in every test case. With different parameters, but the same is created several times. (actually with 'full' parameter it is created 12 times in 2.3) If we cache the different containers during test, we avoid to creating the same container multiple times. As I experienced it can be merged without a conflict into 2.3 and 2.7, but 2.8 and 3.0 conflicts. I have these result on my local setup. Not that big optimalization, but a few second can matter too imo. :) **2.3 before** ```go Time: 8.79 seconds, Memory: 55.75Mb OK (449 tests, 586 assertions) OK src/Symfony/Bundle/FrameworkBundle ``` **2.3 after** ```go Time: 5.85 seconds, Memory: 58.25Mb OK (449 tests, 586 assertions) OK src/Symfony/Bundle/FrameworkBundle ``` ---- **2.7 before** ```go Time: 17.17 seconds, Memory: 81.50Mb OK, but incomplete, skipped, or risky tests! Tests: 753, Assertions: 1098, Skipped: 3. Legacy deprecation notices (45) OK src/Symfony/Bundle/FrameworkBundle ``` **2.7 after** ```go Time: 12.65 seconds, Memory: 88.00Mb OK, but incomplete, skipped, or risky tests! Tests: 753, Assertions: 1098, Skipped: 3. Legacy deprecation notices (41) OK src/Symfony/Bundle/FrameworkBundle ``` ---- **2.8 before** ```go Time: 18.94 seconds, Memory: 88.00Mb OK, but incomplete, skipped, or risky tests! Tests: 787, Assertions: 1159, Skipped: 3. Legacy deprecation notices (89) OK src/Symfony/Bundle/FrameworkBundle ``` **2.8 after** ```go Time: 12.69 seconds, Memory: 94.50Mb OK, but incomplete, skipped, or risky tests! Tests: 787, Assertions: 1159, Skipped: 3. Legacy deprecation notices (85) OK src/Symfony/Bundle/FrameworkBundle ``` ---- **3.0 before** ```go Time: 16.48 seconds, Memory: 73.75Mb OK (741 tests, 1043 assertions) OK src/Symfony/Bundle/FrameworkBundle ``` **3.0 after** ```go Time: 11.49 seconds, Memory: 76.75Mb OK (741 tests, 1043 assertions) OK src/Symfony/Bundle/FrameworkBundle ``` Commits ------- f6a078b [FrameworkBundle] Optimize framework extension tests
…radajozsef) This PR was squashed before being merged into the 2.3 branch (closes #17497). Discussion ---------- [SecurityBundle] Optimize dependency injection tests | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #17366 | License | MIT | Doc PR | - Tests building the same container multiple times. The same solution can be applied as here: #17399. This time I ran comparison tests only on 2.3. (my laptop is really slow) **2.3 before** ```go Time: 14.79 seconds, Memory: 48.25Mb OK (77 tests, 227 assertions) OK src/Symfony/Bundle/SecurityBundle/ ``` **2.3 after** ```go Time: 9.78 seconds, Memory: 48.75Mb OK (77 tests, 227 assertions) OK src/Symfony/Bundle/SecurityBundle/ ``` Commits ------- bf56d2f [SecurityBundle] Optimize dependency injection tests
XmlFrameworkExtensionTest
,YamlFrameworkExtensionTest
andPhpFrameworkExtensionTest
are slow tests. The reason is that the parent test creates the container in every test case. With different parameters, but the same is created several times. (actually with 'full' parameter it is created 12 times in 2.3) If we cache the different containers during test, we avoid to creating the same container multiple times.As I experienced it can be merged without a conflict into 2.3 and 2.7, but 2.8 and 3.0 conflicts.
I have these result on my local setup. Not that big optimalization, but a few second can matter too imo. :)
2.3 before
2.3 after
2.7 before
2.7 after
2.8 before
2.8 after
3.0 before
3.0 after