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

Set COVERAGE_CORE: sysmon for faster tests on 3.12+ #7820

Merged
merged 1 commit into from
Feb 22, 2024

Conversation

hugovk
Copy link
Member

@hugovk hugovk commented Feb 20, 2024

Python 3.12 introduced sys.monitoring, that tools like coverage.py can use to improve performance.

It's not yet the default in coverage.py. To enable, we can set a COVERAGE_CORE=sysmon environment variable, that will switch to the faster mode when available, that is, in Python 3.12 and newer. Older versions will stick to the older method.

For example, on my machine:

test command result
No coverage python3 -m pytest Tests 4269 passed, 224 skipped, 3 xfailed in 48.21s
Coverage: default core python3 -m pytest --cov PIL --cov Tests Tests 4269 passed, 224 skipped, 3 xfailed in 58.15s
Coverage: sysmon core COVERAGE_CORE=sysmon python3 -m pytest --cov PIL --cov Tests Tests 4269 passed, 224 skipped, 3 xfailed in 46.73s

Coverage time on CI, default core -> sysmon core:

CI job before after speedup
AppVeyor 3.12 229.76s (0:03:49) 198.50s (0:03:18) 13.6%
macOS 3.13 68.55s (0:01:08) 62.33s (0:01:02) 9.1%
macOS 3.12 84.63s (0:01:24) 71.83s (0:01:11) 15.1%
Ubuntu 3.13 89.40s (0:01:29) 65.46s (0:01:05) 26.8%
Ubuntu 3.12 91.20s (0:01:31) 67.33s (0:01:07) 26.2%
Windows 3.13 156.69s (0:02:36) 134.59s (0:02:14) 14.1%
Windows 3.12 164.19s (0:02:44) 146.63s (0:02:26) 10.7%
Total 884.42 (0:14:41) 746.67 (0:12:23) 15.6%

I also added the env var to the Cygwin and MinGW workflows, even though they test Python <= 3.11. If they're upgraded to 3.12+ later, it'll take effect.

@radarhere
Copy link
Member

It's not yet the default

Is the reason it's not yet the default, and why https://coverage.readthedocs.io/en/7.4.2/changes.html#version-7-4-0-2023-12-27 lists it as "experimental", just because branch coverage isn't faster? Or is there another reason?

@hugovk
Copy link
Member Author

hugovk commented Feb 20, 2024

Yeah, I think it's both because of branch coverage, and because it's new and using new Python features, so feedback is requested.

If we find any problems, we can give feedback, and easily disable if necessary.

Copy link
Member

@radarhere radarhere left a comment

Choose a reason for hiding this comment

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

I see that it is faster on AppVeyor, macOS and Ubuntu.

I find it harder to say conclusively that it is faster in Windows on GitHub Actions, but if it is theoretically, then ok.

@hugovk
Copy link
Member Author

hugovk commented Feb 22, 2024

Here's three runs of Windows on GitHub Actions with main, 3 x 3.12, then 3 x 3.13:

= 3239 passed, 89 skipped, 3 xfailed, 1 xpassed, 4 warnings in 156.62s (0:02:36) =
= 3239 passed, 89 skipped, 3 xfailed, 1 xpassed, 4 warnings in 156.62s (0:02:36) =
= 3239 passed, 89 skipped, 3 xfailed, 1 xpassed, 4 warnings in 163.58s (0:02:43) =
= 3239 passed, 89 skipped, 3 xfailed, 1 xpassed, 4 warnings in 158.81s (0:02:38) =
= 3239 passed, 89 skipped, 3 xfailed, 1 xpassed, 4 warnings in 158.81s (0:02:38) =
= 3239 passed, 89 skipped, 3 xfailed, 1 xpassed, 4 warnings in 158.81s (0:02:38) =

https://github.com/hugovk/Pillow/actions/runs/7941332092/attempts/1
https://github.com/hugovk/Pillow/actions/runs/7941332092/attempts/2
https://github.com/hugovk/Pillow/actions/runs/7941332092/attempts/3

Then with the PR:

= 3239 passed, 89 skipped, 3 xfailed, 1 xpassed, 4 warnings in 139.70s (0:02:19) =
= 3239 passed, 89 skipped, 3 xfailed, 1 xpassed, 4 warnings in 147.11s (0:02:27) =
= 3239 passed, 89 skipped, 3 xfailed, 1 xpassed, 4 warnings in 150.77s (0:02:30) =
= 3239 passed, 89 skipped, 3 xfailed, 1 xpassed, 4 warnings in 135.98s (0:02:15) =
= 3239 passed, 89 skipped, 3 xfailed, 1 xpassed, 4 warnings in 138.57s (0:02:18) =
= 3239 passed, 89 skipped, 3 xfailed, 1 xpassed, 4 warnings in 137.47s (0:02:17) =

https://github.com/hugovk/Pillow/actions/runs/7986985726/attempts/1
https://github.com/hugovk/Pillow/actions/runs/7986985726/attempts/2
https://github.com/hugovk/Pillow/actions/runs/7986985726/attempts/3

@hugovk hugovk merged commit 6c126fe into python-pillow:main Feb 22, 2024
56 checks passed
@hugovk hugovk deleted the coverage-sysmon branch February 22, 2024 21:51
@radarhere
Copy link
Member

Despite passing on main a mere 11 hours ago, this has started failing in PyPy on Windows - https://github.com/python-pillow/Pillow/actions/runs/8016398970/job/21898259794

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants