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

Do not run SKIPIF section of PHPT test in separate process when it is free of side effects #5998

Merged
merged 1 commit into from
Oct 18, 2024

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Oct 18, 2024

while looking into PHPT performance, I realized that the --SKIPIF-- condition is evaluated in a separate subprocess.

this means a major overhead for a maybe pretty simple side-effect-less condition like:

--SKIPIF--
<?php version_compare(PHP_VERSION, "8.0", ">=")
      or echo "skip because attributes are only available since PHP 8.0"; ?>

I built a small class in which you can pass a string of source-code and it returns whether the given code would have side-effects when evaluated.

In PHPUnit I utilize the detected side-effect-free SKIPIF conditions and evaluate such code in the main-process instead of creating a new one. In case we cannot say with 100% certainty the code does not have side-effects we play save and run it in the subprocess.


when running php ./phpunit tests/end-to-end/event/assert-failure.phpt I can see the following results:

macos:

after this PR: 00:00.070 - 00:00.077
before this PR: 00:00.092 - 00:00.098

-> which means ~20% faster on my mac m1pro on a single test-case.

on windows with

PHP 8.3.11 (cli) (built: Aug 27 2024 21:28:35) (NTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.3.11, Copyright (c) Zend Technologies

after this PR: 00:00.360 - 00:00.395
before this PR: 00:00.406 - 00:00.443

-> seems also roughly ~20% faster
(see how slow running the same test is on windows vs. macos)

refs #5973

Comment on lines +275 to +280
<copy file="${basedir}/vendor/staabm/side-effects-detector/LICENSE" tofile="${basedir}/build/tmp/phar/staabm-side-effects-detector/LICENSE"/>
<copy todir="${basedir}/build/tmp/phar/staabm-side-effects-detector">
<fileset dir="${basedir}/vendor/staabm/side-effects-detector/lib">
<include name="**/*.php" />
</fileset>
</copy>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this correct like that?

@staabm staabm force-pushed the side2 branch 4 times, most recently from 2697a8f to a39878b Compare October 18, 2024 14:55
Copy link

codecov bot commented Oct 18, 2024

Codecov Report

Attention: Patch coverage is 96.87500% with 1 line in your changes missing coverage. Please review.

Project coverage is 94.78%. Comparing base (f22ea1e) to head (0db3be0).
Report is 1 commits behind head on 11.5.

Files with missing lines Patch % Lines
src/Runner/PHPT/PhptTestCase.php 96.87% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               11.5    #5998      +/-   ##
============================================
+ Coverage     94.76%   94.78%   +0.01%     
- Complexity     6807     6814       +7     
============================================
  Files           720      720              
  Lines         21603    21626      +23     
============================================
+ Hits          20473    20498      +25     
+ Misses         1130     1128       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@staabm staabm force-pushed the side2 branch 2 times, most recently from cd00575 to ad2aaeb Compare October 18, 2024 15:12
@staabm staabm marked this pull request as ready for review October 18, 2024 15:18
@sebastianbergmann sebastianbergmann added type/enhancement A new idea that should be implemented feature/phpt End-to-end tests in PHPT format feature/test-runner CLI test runner type/performance Issues related to resource consumption (time and memory) labels Oct 18, 2024
@sebastianbergmann sebastianbergmann added this to the PHPUnit 11.5 milestone Oct 18, 2024
@sebastianbergmann sebastianbergmann merged commit e997803 into sebastianbergmann:11.5 Oct 18, 2024
31 checks passed
@sebastianbergmann sebastianbergmann changed the title Inline SKIPIF evaluation without side-effects Do not run SKIPIF section of PHPT test in separate process when it is free of side effects Oct 18, 2024
@staabm staabm deleted the side2 branch October 19, 2024 05:17
@staabm
Copy link
Contributor Author

staabm commented Oct 20, 2024

xabbuh added a commit to symfony/symfony that referenced this pull request Oct 29, 2024
…staabm)

This PR was merged into the 7.2 branch.

Discussion
----------

[PhpUnitBridge] Don't use `die()` in PHPT `--SKIPIF--`

| Q             | A
| ------------- | ---
| Branch?       | 7.2
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        | --
| License       | MIT

Unlocks a performance optimization in PHPUnit 11.5.x

[PHPUnit 11.5.x will be able to avoid subprocess creation](sebastianbergmann/phpunit#5998), when `--SKIPIF--` code in PHPT tests does not `exit()` or `die()` and the logic is side-effect free (output is allowed).

more details in https://staabm.github.io/2024/10/19/phpunit-codesprint-munich.html

Commits
-------

83b09ba Don't use `die()` in PHPT `--SKIPIF--`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/phpt End-to-end tests in PHPT format 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.

2 participants