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

ISSUE-4798: Memory leaks in TestSuite class #4799

Closed
wants to merge 3 commits into from

Conversation

kandy
Copy link
Contributor

@kandy kandy commented Oct 14, 2021

 - Do not store list of classes in property
  fix: sebastianbergmann#4798
@IonBazan
Copy link
Contributor

IonBazan commented Oct 15, 2021

This has been introduced in #2861 on purpose for some edge case. Let's make sure this PR does not introduce a regression.
Perhaps we could try using a static variable instead?

cc @kubawerlos.

@sebastianbergmann sebastianbergmann added the type/performance Issues related to resource consumption (time and memory) label Oct 15, 2021
@villfa
Copy link
Contributor

villfa commented Nov 9, 2021

In order to reduce the memory usage I propose to store only the number of declared classes instead of the whole list of declared classes:
BEFORE

$declaredClasses = get_declared_classes();
// some code
$newClasses = array_diff(get_declared_classes(), $declaredClasses);

AFTER

$numberOfDeclaredClasses = count(get_declared_classes());
// some code
$newClasses = array_slice(get_declared_classes(), $numberOfDeclaredClasses);

@kandy
Copy link
Contributor Author

kandy commented Nov 9, 2021

In order to reduce the memory usage I propose to store only the number of declared classes instead of the whole list of declared classes:

Based on https://www.php.net/manual/en/function.get-declared-classes.php

No particular order is guaranteed for the get_declared_classes() return value.

It's maybe not the best idea to depend on behavior that may be changed, but let's try

@villfa
Copy link
Contributor

villfa commented Nov 9, 2021

I've missed this change. Thanks

EDIT here the full quote:

Previously get_declared_classes() always returned parent classes before child classes. This is no longer the case. No particular order is guaranteed for the get_declared_classes() return value.

With this context I think we're safe.

 - use pointer to store defined classes state
@kandy
Copy link
Contributor Author

kandy commented Nov 9, 2021

@villfa I have implemented your suggestion

@sebastianbergmann
Copy link
Owner

When I apply this patch to 9.5 then I get the following test failure:

1) /usr/local/src/phpunit/tests/end-to-end/regression/GitHub/2972.phpt
Failed asserting that string matches format description.
--- Expected
+++ Actual
@@ @@
 
 Warning:       Test case class not matching filename is deprecated
                in /usr/local/src/phpunit/tests/end-to-end/regression/GitHub/2972/unconventiallyNamedIssue2972Test.php
+               Class name was 'PhptTestCase', expected 'unconventiallyNamedIssue2972Test'
+Warning:       Test case class not matching filename is deprecated
+               in /usr/local/src/phpunit/tests/end-to-end/regression/GitHub/2972/unconventiallyNamedIssue2972Test.php
                Class name was 'Issue2972Test', expected 'unconventiallyNamedIssue2972Test'
 
 ..                                                                  2 / 2 (100%)
 
-Time: %s, Memory: %s
+Time: 00:00.051, Memory: 4.00 MB
 
 OK (2 tests, 2 assertions)

@kandy
Copy link
Contributor Author

kandy commented Dec 6, 2021

@sebastianbergmann For 9.x there is one more usage of declaredClasses property in the class that should be replaced with declaredClassesPointer. see https://github.com/sebastianbergmann/phpunit/compare/master...kandy:Issue-4798-9x?expand=1#diff-ce07bbf9be7fe14e3102ab699c8a2d6c2a995bc23f8f93871fb4f3dde098dfaaR392 (line: 392)

@sebastianbergmann
Copy link
Owner

For 9.x there is one more usage of declaredClasses property

And by "9.x" you mean "8.x", right? Because that is the target of this pull request.

@kandy
Copy link
Contributor Author

kandy commented Dec 7, 2021

For 9.x there is one more usage of declaredClasses property

And by "9.x" you mean "8.x", right? Because that is the target of this pull request.

no 9.5, see your previous comment #4799 (comment)

@sebastianbergmann
Copy link
Owner

no 9.5, see your previous comment #4799 (comment)

My bad, too early in the morning :)

@kandy
Copy link
Contributor Author

kandy commented Jan 12, 2022

@sebastianbergmann What is the status of this OR? Is any further action is needed to merge it?

sebastianbergmann added a commit that referenced this pull request Jan 14, 2022
@sebastianbergmann
Copy link
Owner

I merged these changes into 8.5. I merged them from there to 9.5 and made the change you suggested in #4799 (comment) in e169850. The code in question does not exist in master anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/performance Issues related to resource consumption (time and memory)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants