Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Closed

Conversation

paradajozsef
Copy link
Contributor

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 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

Time: 8.79 seconds, Memory: 55.75Mb
OK (449 tests, 586 assertions)
OK src/Symfony/Bundle/FrameworkBundle

2.3 after

Time: 5.85 seconds, Memory: 58.25Mb
OK (449 tests, 586 assertions)
OK src/Symfony/Bundle/FrameworkBundle

2.7 before

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

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

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

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

Time: 16.48 seconds, Memory: 73.75Mb
OK (741 tests, 1043 assertions)
OK src/Symfony/Bundle/FrameworkBundle

3.0 after

Time: 11.49 seconds, Memory: 76.75Mb
OK (741 tests, 1043 assertions)
OK src/Symfony/Bundle/FrameworkBundle

$dataHash = md5(serialize($data));

if (!isset(self::$containerCache[$file][$dataHash])) {

Copy link
Member

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?

Copy link
Contributor Author

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

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 ?

@javiereguiluz
Copy link
Member

@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.

@paradajozsef
Copy link
Contributor Author

@javiereguiluz thank you. :) renamed $dataHash to $cacheKey.

$container = $this->createContainer($data);
$container->registerExtension(new FrameworkExtension());
$this->loadFromFile($container, $file);
$cacheKey = md5(serialize($data));
Copy link
Member

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?

Copy link
Contributor Author

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! :)

@xabbuh
Copy link
Member

xabbuh commented Jan 16, 2016

👍

Status: Reviewed


if (!isset(self::$containerCache[$cacheKey])) {
$container = $this->createContainer($data);

Copy link
Member

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?

@paradajozsef
Copy link
Contributor Author

@fabpot Yes, it should have been done so for the first time. Anyway, I changed the if statement.

@fabpot
Copy link
Member

fabpot commented Jan 17, 2016

Thank you @paradajozsef.

fabpot added a commit that referenced this pull request Jan 17, 2016
…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
@fabpot fabpot closed this Jan 17, 2016
@paradajozsef paradajozsef deleted the optimize-fwbundle-tests branch January 21, 2016 08:48
fabpot added a commit that referenced this pull request Jan 23, 2016
…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
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.

5 participants