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

Inline SKIPIF evaluation without side-effects #5974

Closed
wants to merge 1 commit into from

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Sep 28, 2024

Proof of concept

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)


Possible future idea

  • Don't use subprocess for —CLEAN— as long as the code cannot modify the parent process (e.g. file IO is fine within the parent process)

I am pretty sure this needs more work but wanted to have opinions first, whether this is acceptable.

refs #5973

Copy link

codecov bot commented Sep 28, 2024

Codecov Report

Attention: Patch coverage is 70.00000% with 9 lines in your changes missing coverage. Please review.

Project coverage is 94.63%. Comparing base (a82cc05) to head (6abddb3).
Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
src/Runner/PHPT/PhptTestCase.php 70.00% 9 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #5974      +/-   ##
============================================
- Coverage     94.67%   94.63%   -0.05%     
- Complexity     6406     6413       +7     
============================================
  Files           694      694              
  Lines         19189    19212      +23     
============================================
+ Hits          18167    18181      +14     
- Misses         1022     1031       +9     

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

@staabm staabm force-pushed the side-effects branch 3 times, most recently from 57034fa to 6f6390e Compare September 29, 2024 07:15
@clxmstaab clxmstaab force-pushed the side-effects branch 2 times, most recently from 1e344b0 to 2f10d5e Compare October 1, 2024 16:21
clxmstaab added a commit to staabm/patchwork that referenced this pull request Oct 11, 2024
To unlock PHPUnit side-effect-free in-process --SKIPIF-- evaluation, we
use regular echo instead of die().
That way PHPunit can detect whether conditions may be evaluated in the
main-process to reduce sub-process creation overhead.

see sebastianbergmann/phpunit#5974
@staabm
Copy link
Contributor Author

staabm commented Oct 11, 2024

Tested this PR on a real world project with antecedent/patchwork#168 (and described the results in the PR)

clxmstaab added a commit to staabm/patchwork that referenced this pull request Oct 11, 2024
To unlock PHPUnit side-effect-free in-process --SKIPIF-- evaluation, we
use regular echo instead of die().
That way PHPunit can detect whether conditions may be evaluated in the
main-process to reduce sub-process creation overhead.

see sebastianbergmann/phpunit#5974
}

foreach ($sideEffects as $sideEffect) {
if ($sideEffect === SideEffect::STANDARD_OUTPUT) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could even report a SkipIf condition to be broken, when it does not contain a standard-out side-effect

@staabm
Copy link
Contributor Author

staabm commented Oct 18, 2024

todo

  • test-case (events)
  • build.xml
  • target version 11.5

@staabm
Copy link
Contributor Author

staabm commented Oct 18, 2024

retargeted in #5998

@staabm staabm closed this Oct 18, 2024
@staabm staabm deleted the side-effects branch October 18, 2024 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant