-
Notifications
You must be signed in to change notification settings - Fork 180
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
Use private properties to store sensible and big variables to improve memory usage (Enhancement) #218
Comments
yeah .. I think the biggest memory hog is the container etc .. which I think leaks memory .. sure send a PR! |
Perfect! I'll work on this :) |
Yesss, +1 on improving memory usage! You may want to take a look at this: http://kriswallsmith.net/post/18029585104/faster-phpunit It also helps to force a garbage collection cycle in the tearDown() method (however, if you are using the phpunit-bridge note that the bridge currently disables garbage collection). |
IIRC, this Bundle inherits from Symfony test class, is the |
It just shuts down the kernel in |
Maybe it would be interesting to submit the same patch to Symfony? |
Yes and no. The Symfony test classes do not set any properties (except for the kernel, which is also being shut down). The The patch mentioned above is basically just a shortcut for the lazy developer - I'm not sure if this should be provided/encouraged by the framework :) |
@alexislefebvre , Maybe... The |
@tackerm , yes, you are right. Using reflection I found an average o 5 Kb increase in memory usage for smaller tests. For bigger ones, instead, the average memory freed is about 30Kb... But this, obviously, depends on the kind of test, the number of variables, ecc... Anyway I agree with you about: each class should take care of tear down itself... The reflection is a temporary workaround, not a definitive solution... |
I think this is a very big task, so may be better to split it into smaller tasks, as one for the More, with the occasion, may be useful to also move one level up some methods, to reduce the number of lines in the What do you think about? This kind of reorganization may be also helpful to complete issue #6... Anyway in the next days I will better examine the situation and provide a more detailed list of possible tasks. |
Just sharing some early-morning-thoughts:
|
yeah a refactoring would be great to do for 2.0. see also he oldest open ticket #6 |
@lsmith77 , yes, I saw it and linked too! :) I agree, it may be very useful.
|
Source: https://phpunit.de/manual/current/en/fixtures.html The |
I think that the first step to take is to start using properties instead of local variables. Then we'll can (and I'll can too, as at the moment I'm still understanding the code) decide if the best choice is a Take the |
I'm refactoring some of my test class to use less memory as I had some problems with large memory usage on my CI server.
Going deeper in the code to find issues I came up with a
trait
that can teardown automatically the tests and set all properties tonull
to free up memory space.The
trait
also provides some useful methods to better manage internal variables and resources, storing them in some properties that are then set tonull
.This bundle seems to use a lot of memory as it creates a lot of very big variables.
It may be sufficient to use properties to store objects like kernel, clients, and similar thing, and, adding a simple
tearDown()
method, set those tonull
to free up memory space and improve tests performance.Maybe this helpful to you?
The text was updated successfully, but these errors were encountered: