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

Control when PHP's garbage collector is triggered #5368

Merged
merged 6 commits into from
Jul 18, 2023

Conversation

sebastianbergmann
Copy link
Owner

@sebastianbergmann sebastianbergmann commented May 23, 2023

When the PHP runtime automatically performs garbage collection then this may happen in the middle of the preparation (fixture setup) of a test or in the middle of the execution of a test. This can have a negative impact on test execution performance.

Solution proposed by @edorian in a conversation yesterday:

  • Deactivate automatic garbage collection using gc_disable() before the first test is run
  • Trigger garbage collection using gc_collect_cycles() before the first test is run
  • Trigger garbage collection using gc_collect_cycles() after each n-th test
  • Trigger garbage collection after using gc_collect_cycles() after the last test was run
  • Activate automatic garbage collection using gc_enable() after the last test was run
  • Implement GarbageCollectionHandler that implements the above using PHPUnit's event system
  • Implement XML configuration file settings to configure this functionality
  • Register GarbageCollectionHandler when feature is enabled in XML configuration

@sebastianbergmann sebastianbergmann added type/enhancement A new idea that should be implemented feature/test-runner CLI test runner type/performance Issues related to resource consumption (time and memory) labels May 23, 2023
@codecov
Copy link

codecov bot commented May 23, 2023

Codecov Report

Merging #5368 (6b73f0e) into main (0abe06b) will increase coverage by 0.06%.
The diff coverage is 100.00%.

@@             Coverage Diff              @@
##               main    #5368      +/-   ##
============================================
+ Coverage     86.67%   86.73%   +0.06%     
- Complexity     6170     6198      +28     
============================================
  Files           652      660       +8     
  Lines         19635    19727      +92     
============================================
+ Hits          17019    17111      +92     
  Misses         2616     2616              
Impacted Files Coverage Δ
src/Event/Emitter/DispatchingEmitter.php 95.94% <100.00%> (+0.08%) ⬆️
...nt/Events/TestRunner/GarbageCollectionDisabled.php 100.00% <100.00%> (ø)
...ent/Events/TestRunner/GarbageCollectionEnabled.php 100.00% <100.00%> (ø)
...t/Events/TestRunner/GarbageCollectionTriggered.php 100.00% <100.00%> (ø)
src/Event/Facade.php 89.04% <100.00%> (+0.22%) ⬆️
...ner/GarbageCollection/GarbageCollectionHandler.php 100.00% <100.00%> (ø)
...lection/Subscriber/ExecutionFinishedSubscriber.php 100.00% <100.00%> (ø)
...llection/Subscriber/ExecutionStartedSubscriber.php 100.00% <100.00%> (ø)
...Runner/GarbageCollection/Subscriber/Subscriber.php 100.00% <100.00%> (ø)
...geCollection/Subscriber/TestFinishedSubscriber.php 100.00% <100.00%> (ø)
... and 6 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@sebastianbergmann sebastianbergmann self-assigned this May 26, 2023
@sebastianbergmann sebastianbergmann force-pushed the controlled-garbage-collection branch 2 times, most recently from 5ec000f to f132c80 Compare May 27, 2023 04:38
@sebastianbergmann sebastianbergmann marked this pull request as ready for review May 27, 2023 05:04
@sebastianbergmann sebastianbergmann added this to the PHPUnit 10.3 milestone May 27, 2023
@sebastianbergmann sebastianbergmann force-pushed the controlled-garbage-collection branch 6 times, most recently from 3b7edd7 to 032c0f0 Compare June 3, 2023 05:07
@sebastianbergmann sebastianbergmann force-pushed the controlled-garbage-collection branch 4 times, most recently from 805212a to d7d70ea Compare June 27, 2023 14:21
@sebastianbergmann sebastianbergmann merged commit 4f7910e into main Jul 18, 2023
40 of 42 checks passed
@sebastianbergmann sebastianbergmann deleted the controlled-garbage-collection branch July 18, 2023 05:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/test-runner CLI test runner type/enhancement A new idea that should be implemented 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

1 participant