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

Restore zero copy writes on Python 3.12.9+/3.13.2+ #10137

Merged
merged 7 commits into from
Feb 5, 2025
Merged

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Dec 6, 2024

TODO

  • Hold until 3.13.2 release day: Tuesday, 2025-02-04
  • Wait for GitHub to update 3.13 runners to 3.13.2
  • Re-run benchmarks
  • If benchmarks show the perf regression is fixed, this should be good to move forward and do a new release

What do these changes do?

Restore zero copy support on Python 3.12.9+/3.13.2+ (unreleased at this time)
CVE-2024-12254 aka GHSA-fw89-6wjj-8j95 is fixed on these Python versions

Are there changes in behavior for the user?

The performance regression introduced by disabling zero copy writes in #10125 will be resolved

The relevant benchmarks (keep in mind we are benchmarking disabling zero copy writes), and this PR seeks to restore the performance:

test_one_hundred_get_requests_with_1024_chunked_payload +3% (writelines is a bit worse for tiny payloads)
test_one_hundred_get_requests_with_512kib_chunked_payload -21% (writelines is a lot better for large payloads)
test_one_hundred_get_requests_with_30000_chunked_payload -4% (writelines is a slightly better for medium size payloads)

Since we already have to branch here, I also added MIN_PAYLOAD_FOR_WRITELINES to 2048 to ensure we no longer take the 3% performance hit for writelines with small payloads

@bdraco bdraco changed the title Restore zero copy support on Python 3.12.9+/3.13.2+ Restore zero copy writes on Python 3.12.9+/3.13.2+ Dec 6, 2024
@bdraco bdraco added backport-3.11 Trigger automatic backporting to the 3.11 release branch by Patchback robot backport-3.12 Trigger automatic backporting to the 3.12 release branch by Patchback robot labels Dec 6, 2024
Copy link

codspeed-hq bot commented Dec 6, 2024

CodSpeed Performance Report

Merging #10137 will improve performances by 18.02%

Comparing restore_zero_copy (9645236) with master (8bf5d4d)

Summary

⚡ 1 improvements
✅ 46 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
test_one_hundred_get_requests_with_512kib_chunked_payload[pyloop] 222.4 ms 188.4 ms +18.02%

Copy link

codecov bot commented Dec 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.76%. Comparing base (8bf5d4d) to head (9645236).
Report is 2 commits behind head on master.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10137      +/-   ##
==========================================
- Coverage   98.76%   98.76%   -0.01%     
==========================================
  Files         122      122              
  Lines       37048    37123      +75     
  Branches     2042     2044       +2     
==========================================
+ Hits        36590    36664      +74     
- Misses        318      319       +1     
  Partials      140      140              
Flag Coverage Δ
CI-GHA 98.65% <100.00%> (+<0.01%) ⬆️
OS-Linux 98.33% <100.00%> (+<0.01%) ⬆️
OS-Windows 96.25% <100.00%> (+0.01%) ⬆️
OS-macOS 97.45% <100.00%> (+0.01%) ⬆️
Py-3.10.11 97.34% <100.00%> (+0.01%) ⬆️
Py-3.10.16 97.91% <100.00%> (+<0.01%) ⬆️
Py-3.11.11 98.00% <100.00%> (+<0.01%) ⬆️
Py-3.11.9 97.42% <100.00%> (+0.01%) ⬆️
Py-3.12.8 98.43% <100.00%> (+<0.01%) ⬆️
Py-3.13.1 98.42% <100.00%> (+<0.01%) ⬆️
Py-3.9.13 97.23% <100.00%> (+0.01%) ⬆️
Py-3.9.21 97.79% <100.00%> (+<0.01%) ⬆️
Py-pypy7.3.16 97.38% <100.00%> (+0.01%) ⬆️
VM-macos 97.45% <100.00%> (+0.01%) ⬆️
VM-ubuntu 98.33% <100.00%> (+<0.01%) ⬆️
VM-windows 96.25% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Dec 6, 2024
aiohttp/http_writer.py Outdated Show resolved Hide resolved
CHANGES/10137.misc.rst Outdated Show resolved Hide resolved
aiohttp/http_writer.py Outdated Show resolved Hide resolved
@webknjaz

This comment was marked as resolved.

@webknjaz

This comment was marked as resolved.

bdraco and others added 5 commits December 6, 2024 11:23
CVE-2024-12254 aka GHSA-fw89-6wjj-8j95 is fixed on these
Python versions
Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <[email protected]>
@bdraco bdraco force-pushed the restore_zero_copy branch from 894af34 to 85b21f7 Compare December 6, 2024 17:23
@bdraco
Copy link
Member Author

bdraco commented Feb 5, 2025

@bdraco
Copy link
Member Author

bdraco commented Feb 5, 2025

as soon as actions/python-versions#331 merges we can re-run

@webknjaz
Copy link
Member

webknjaz commented Feb 5, 2025

It's merged!

@bdraco
Copy link
Member Author

bdraco commented Feb 5, 2025

Looks like we are still getting 3.13.1

Successfully set up CPython (3.13.1)

@bdraco
Copy link
Member Author

bdraco commented Feb 5, 2025

There we go

Merging #10137 will improve performances by 18.02%

@bdraco bdraco marked this pull request as ready for review February 5, 2025 17:07
@bdraco bdraco requested a review from asvetlov as a code owner February 5, 2025 17:07
@bdraco bdraco enabled auto-merge (squash) February 5, 2025 17:11
@bdraco bdraco merged commit 25c7f23 into master Feb 5, 2025
37 checks passed
@bdraco bdraco deleted the restore_zero_copy branch February 5, 2025 17:18
Copy link
Contributor

patchback bot commented Feb 5, 2025

Backport to 3.11: 💔 cherry-picking failed — conflicts found

❌ Failed to cleanly apply 25c7f23 on top of patchback/backports/3.11/25c7f2382be9b5e03b8d22671f36a2f6fb07221a/pr-10137

Backporting merged PR #10137 into master

  1. Ensure you have a local repo clone of your fork. Unless you cloned it
    from the upstream, this would be your origin remote.
  2. Make sure you have an upstream repo added as a remote too. In these
    instructions you'll refer to it by the name upstream. If you don't
    have it, here's how you can add it:
    $ git remote add upstream https://github.com/aio-libs/aiohttp.git
  3. Ensure you have the latest copy of upstream and prepare a branch
    that will hold the backported code:
    $ git fetch upstream
    $ git checkout -b patchback/backports/3.11/25c7f2382be9b5e03b8d22671f36a2f6fb07221a/pr-10137 upstream/3.11
  4. Now, cherry-pick PR Restore zero copy writes on Python 3.12.9+/3.13.2+ #10137 contents into that branch:
    $ git cherry-pick -x 25c7f2382be9b5e03b8d22671f36a2f6fb07221a
    If it'll yell at you with something like fatal: Commit 25c7f2382be9b5e03b8d22671f36a2f6fb07221a is a merge but no -m option was given., add -m 1 as follows instead:
    $ git cherry-pick -m1 -x 25c7f2382be9b5e03b8d22671f36a2f6fb07221a
  5. At this point, you'll probably encounter some merge conflicts. You must
    resolve them in to preserve the patch from PR Restore zero copy writes on Python 3.12.9+/3.13.2+ #10137 as close to the
    original as possible.
  6. Push this branch to your fork on GitHub:
    $ git push origin patchback/backports/3.11/25c7f2382be9b5e03b8d22671f36a2f6fb07221a/pr-10137
  7. Create a PR, ensure that the CI is green. If it's not — update it so that
    the tests and any other checks pass. This is it!
    Now relax and wait for the maintainers to process your pull request
    when they have some cycles to do reviews. Don't worry — they'll tell you if
    any improvements are necessary when the time comes!

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

Copy link
Contributor

patchback bot commented Feb 5, 2025

Backport to 3.12: 💔 cherry-picking failed — conflicts found

❌ Failed to cleanly apply 25c7f23 on top of patchback/backports/3.12/25c7f2382be9b5e03b8d22671f36a2f6fb07221a/pr-10137

Backporting merged PR #10137 into master

  1. Ensure you have a local repo clone of your fork. Unless you cloned it
    from the upstream, this would be your origin remote.
  2. Make sure you have an upstream repo added as a remote too. In these
    instructions you'll refer to it by the name upstream. If you don't
    have it, here's how you can add it:
    $ git remote add upstream https://github.com/aio-libs/aiohttp.git
  3. Ensure you have the latest copy of upstream and prepare a branch
    that will hold the backported code:
    $ git fetch upstream
    $ git checkout -b patchback/backports/3.12/25c7f2382be9b5e03b8d22671f36a2f6fb07221a/pr-10137 upstream/3.12
  4. Now, cherry-pick PR Restore zero copy writes on Python 3.12.9+/3.13.2+ #10137 contents into that branch:
    $ git cherry-pick -x 25c7f2382be9b5e03b8d22671f36a2f6fb07221a
    If it'll yell at you with something like fatal: Commit 25c7f2382be9b5e03b8d22671f36a2f6fb07221a is a merge but no -m option was given., add -m 1 as follows instead:
    $ git cherry-pick -m1 -x 25c7f2382be9b5e03b8d22671f36a2f6fb07221a
  5. At this point, you'll probably encounter some merge conflicts. You must
    resolve them in to preserve the patch from PR Restore zero copy writes on Python 3.12.9+/3.13.2+ #10137 as close to the
    original as possible.
  6. Push this branch to your fork on GitHub:
    $ git push origin patchback/backports/3.12/25c7f2382be9b5e03b8d22671f36a2f6fb07221a/pr-10137
  7. Create a PR, ensure that the CI is green. If it's not — update it so that
    the tests and any other checks pass. This is it!
    Now relax and wait for the maintainers to process your pull request
    when they have some cycles to do reviews. Don't worry — they'll tell you if
    any improvements are necessary when the time comes!

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

bdraco added a commit that referenced this pull request Feb 5, 2025
Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <[email protected]>
(cherry picked from commit 25c7f23)
bdraco added a commit that referenced this pull request Feb 5, 2025
Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <[email protected]>
(cherry picked from commit 25c7f23)
bdraco added a commit that referenced this pull request Feb 5, 2025
bdraco added a commit that referenced this pull request Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-3.11 Trigger automatic backporting to the 3.11 release branch by Patchback robot backport-3.12 Trigger automatic backporting to the 3.12 release branch by Patchback robot bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants