Skip to content
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

Values used in assertions are exported for Test\AssertionSucceeded events #5183

Closed
muzcb opened this issue Feb 8, 2023 · 9 comments
Closed
Assignees
Labels
feature/events Issues related to PHPUnit's event system type/performance Issues related to resource consumption (time and memory) version/10 Something affects PHPUnit 10

Comments

@muzcb
Copy link

muzcb commented Feb 8, 2023

Since PHPUnit 10, all assertion results will be handed to DispatchingEmitter, which in turn will call

(new Exporter)->export($value)

each time, including for succeeded assertions. If the values can be complex object graphs (similar to those described in issue #4965) that will cause the memory usage and runtime to multiply.

@sebastianbergmann sebastianbergmann added type/performance Issues related to resource consumption (time and memory) feature/events Issues related to PHPUnit's event system version/10 Something affects PHPUnit 10 labels Feb 8, 2023
@sebastianbergmann sebastianbergmann changed the title PHPUnit 10 Performance issues due to Exporter Values used in assertions are exported for Test\AssertionSucceeded and Test\AssertionFailed events Feb 8, 2023
@Slamdunk
Copy link
Contributor

Slamdunk commented Feb 8, 2023

I can confirm this can have a huge impact: on my biggest project exporting $value makes the test suite run 3x times slower than stripping away that single line of code from PHPUnit.

@sebastianbergmann
Copy link
Owner

I have to say that I am surprised that this has such a huge impact, simply because I have never used assertions on object graphs so large that exporting them became noticably expensive.

@Slamdunk
Copy link
Contributor

Slamdunk commented Feb 8, 2023

The most recurring use case for me is where you have a variable that might be an object or null, so the first assertion on the variable is assertNotNull:

$myBigObject = getMyBigObjectOrNull();
self::assertNotNull($myBigObject);
self::assertTrue($myBigObject->active()); // And so on

I have a hundred of snippets like this in my test folder.

@sebastianbergmann sebastianbergmann changed the title Values used in assertions are exported for Test\AssertionSucceeded and Test\AssertionFailed events Values used in assertions are exported for Test\AssertionSucceeded events Feb 8, 2023
@sebastianbergmann sebastianbergmann self-assigned this Feb 8, 2023
@sebastianbergmann
Copy link
Owner

Thank you, @muzcb and @Slamdunk for bringing this to my attention!

With the changes in c2fcb8f, we no longer export values used in assertions to emit the Test\AssertionSucceeded event. The Test\AssertionSucceeded::value() message has been marked as deprecated, it will be removed in PHPUnit 11. Until then, this method will always return ''.

@Slamdunk
Copy link
Contributor

Slamdunk commented Feb 8, 2023

Thank you very much for your support @sebastianbergmann

@sakarikl
Copy link

sakarikl commented Feb 9, 2023

After this change PhpUnit 10 is actually faster than 9.5 or 9.6 for us.

Before this change test suite took around 8 minutes with PhpUnit 10, now after this it took only under 2 minutes.

with 9.6/9.5 it takes about 3 minutes.

@sebastianbergmann
Copy link
Owner

@sakarikl That is good to hear, thanks! It is also surprising to hear, as PHPUnit 10 "does more" (event system) than PHPUnit 9, so I have to wonder where this improvement is coming from.

@sakarikl
Copy link

sakarikl commented Feb 9, 2023

Only change for us was using attributes instead of phpdoc (in covers and dataprovider) and changing data providers to statics.

@sakarikl
Copy link

sakarikl commented Feb 9, 2023

oh. and paratest was also updated from 6 to 7. Those were all run with WrapperRunner with 4 processes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/events Issues related to PHPUnit's event system type/performance Issues related to resource consumption (time and memory) version/10 Something affects PHPUnit 10
Projects
None yet
Development

No branches or pull requests

4 participants