Skip to content

Add masked WebSocket read benchmarks and fix read benchmark backpressure - #13561

Merged
bdraco merged 2 commits into
masterfrom
masked-ws-read-benchmarks
Aug 28, 2026
Merged

Add masked WebSocket read benchmarks and fix read benchmark backpressure#13561
bdraco merged 2 commits into
masterfrom
masked-ws-read-benchmarks

Conversation

@bdraco

@bdraco bdraco commented Aug 28, 2026

Copy link
Copy Markdown
Member

What do these changes do?

The read benchmarks only fed unmasked frames, so the masked path a server takes for every frame from a client was invisible to CodSpeed; this adds masked variants for small text and large binary messages. It also fixes the existing read benchmarks; they stored an AssertionError from pause_reading after the eighth large frame and measured the early return path for the remaining feeds. The parser also stops parsing once the queue crosses its limit, so each benchmark round now uses a fresh reader with a queue limit the batch cannot reach.

CodSpeed will show a large regression on the large binary read benchmark; that is really restoring the benchmark to its original design. We missed _upgraded = True in the original, and after #11966 went in it would latch the AssertionError from pause_reading failing, so what looked like an improvement was the benchmark doing effectively nothing after 8 frames.

Are there changes in behavior for the user?

No, benchmarks only.

Is it a substantial burden for the maintainers to support this?

No, the new benchmarks follow the shape of the existing ones.

Related issue number

Noticed while benchmarking #13559.

Checklist

  • I think the code is well written
  • Unit tests for the changes exist N/A, this is a benchmark change
  • Documentation reflects the changes N/A
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt N/A, already listed
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES/ folder
    • name it <issue_or_pr_num>.<type>.rst (e.g. 588.bugfix.rst)

    • if you don't have an issue number, change it to the pull request
      number after creating the PR

      • .bugfix: A bug fix for something the maintainers deemed an
        improper undesired behavior that got corrected to match
        pre-agreed expectations.
      • .feature: A new behavior, public APIs. That sort of stuff.
      • .deprecation: A declaration of future API removals and breaking
        changes in behavior.
      • .breaking: When something public is removed in a breaking way.
        Could be deprecated in an earlier release.
      • .doc: Notable updates to the documentation structure or build
        process.
      • .packaging: Notes for downstreams about unobvious side effects
        and tooling. Changes in the test invocation considerations and
        runtime assumptions.
      • .contrib: Stuff that affects the contributor experience. e.g.
        Running tests, building the docs, setting up the development
        environment.
      • .misc: Changes that are hard to assign to any of the above
        categories.
    • Make sure to use full sentences with correct case and punctuation,
      for example:

      Fixed issue with non-ascii contents in doctest text files
      -- by :user:`contributor-gh-handle`.

      Use the past tense or the present tense a non-imperative mood,
      referring to what's changed compared to the last released version
      of this project.

Drafted with Claude Code (Fable 5); reviewed by @bdraco.

@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Aug 28, 2026
@bdraco bdraco added backport-3.14 Trigger automatic backporting to the 3.14 release branch by Patchback robot backport-3.15 Trigger automatic backporting to the 3.15 release branch by Patchback robot labels Aug 28, 2026
@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.02%. Comparing base (4047e5b) to head (a82fe05).
⚠️ Report is 2 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #13561   +/-   ##
=======================================
  Coverage   99.02%   99.02%           
=======================================
  Files         135      135           
  Lines       50454    50481   +27     
  Branches     2647     2650    +3     
=======================================
+ Hits        49961    49988   +27     
  Misses        370      370           
  Partials      123      123           
Flag Coverage Δ
Autobahn 22.03% <20.58%> (+<0.01%) ⬆️
CI-GHA 98.91% <100.00%> (+<0.01%) ⬆️
OS-Linux 98.69% <100.00%> (+<0.01%) ⬆️
OS-Windows 97.09% <100.00%> (+<0.01%) ⬆️
OS-macOS 97.97% <100.00%> (+<0.01%) ⬆️
Py-3.10 98.12% <100.00%> (+<0.01%) ⬆️
Py-3.11 98.35% <100.00%> (+<0.01%) ⬆️
Py-3.12 98.43% <100.00%> (+<0.01%) ⬆️
Py-3.13 98.42% <100.00%> (-0.01%) ⬇️
Py-3.14 98.45% <100.00%> (-0.01%) ⬇️
Py-3.14t 97.61% <100.00%> (-0.01%) ⬇️
Py-pypy-3.11 97.42% <100.00%> (-0.01%) ⬇️
VM-macos 97.97% <100.00%> (+<0.01%) ⬆️
VM-ubuntu 98.69% <100.00%> (+<0.01%) ⬆️
VM-windows 97.09% <100.00%> (+<0.01%) ⬆️
cython-coverage 83.10% <ø> (+<0.01%) ⬆️

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

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

@bdraco

bdraco commented Aug 28, 2026

Copy link
Copy Markdown
Member Author

This will show as a regression but its really restoring the benchmark to original design. We missed _upgraded = True in the original and after #11966 went in, it would latch the AssertionError from pause_reading failing so what looked like an improvement was it just doing effectively nothing after 8 frames.

@codspeed-hq

codspeed-hq Bot commented Aug 28, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 94.92%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 2 (👁 2) regressed benchmarks
✅ 92 untouched benchmarks
🆕 2 new benchmarks
⏩ 83 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
🆕 test_read_one_hundred_masked_large_binary_websocket_messages N/A 60.1 ms N/A
🆕 test_read_one_hundred_masked_websocket_text_messages N/A 667.1 µs N/A
👁 test_read_one_hundred_websocket_text_messages 464.2 µs 580.3 µs -20%
👁 test_read_large_binary_websocket_messages 100.6 µs 31,129.3 µs -99.68%

Comparing masked-ws-read-benchmarks (a82fe05) with master (4047e5b)

Open in CodSpeed

Footnotes

  1. 83 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@bdraco
bdraco marked this pull request as ready for review August 28, 2026 02:48
@greptile-apps

greptile-apps Bot commented Aug 28, 2026

Copy link
Copy Markdown

Confidence Score: 4/5

The PR appears safe to merge, though the timed reader construction should be excluded to keep the parser benchmarks focused and comparable.

The benchmark now avoids queue accumulation and exercises masked frames, but every measurement includes protocol, queue, and reader initialization that can be mistaken for parser performance.

Files Needing Attention: tests/test_benchmarks_http_websocket.py

Reviews (1): Last reviewed commit: "Add news fragment for benchmark changes" | Re-trigger Greptile

Comment thread tests/test_benchmarks_http_websocket.py
@bdraco
bdraco merged commit 148205f into master Aug 28, 2026
59 of 61 checks passed
@bdraco
bdraco deleted the masked-ws-read-benchmarks branch August 28, 2026 02:54
@patchback

patchback Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

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

❌ Failed to cleanly apply 148205f on top of patchback/backports/3.15/148205f2fdc477ad3e4de0439d817b2a495ccf1e/pr-13561

Backporting merged PR #13561 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.15/148205f2fdc477ad3e4de0439d817b2a495ccf1e/pr-13561 upstream/3.15
  4. Now, cherry-pick PR Add masked WebSocket read benchmarks and fix read benchmark backpressure #13561 contents into that branch:
    $ git cherry-pick -x 148205f2fdc477ad3e4de0439d817b2a495ccf1e
    If it'll yell at you with something like fatal: Commit 148205f2fdc477ad3e4de0439d817b2a495ccf1e is a merge but no -m option was given., add -m 1 as follows instead:
    $ git cherry-pick -m1 -x 148205f2fdc477ad3e4de0439d817b2a495ccf1e
  5. At this point, you'll probably encounter some merge conflicts. You must
    resolve them in to preserve the patch from PR Add masked WebSocket read benchmarks and fix read benchmark backpressure #13561 as close to the
    original as possible.
  6. Push this branch to your fork on GitHub:
    $ git push origin patchback/backports/3.15/148205f2fdc477ad3e4de0439d817b2a495ccf1e/pr-13561
  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.

@patchback

patchback Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

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

❌ Failed to cleanly apply 148205f on top of patchback/backports/3.14/148205f2fdc477ad3e4de0439d817b2a495ccf1e/pr-13561

Backporting merged PR #13561 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.14/148205f2fdc477ad3e4de0439d817b2a495ccf1e/pr-13561 upstream/3.14
  4. Now, cherry-pick PR Add masked WebSocket read benchmarks and fix read benchmark backpressure #13561 contents into that branch:
    $ git cherry-pick -x 148205f2fdc477ad3e4de0439d817b2a495ccf1e
    If it'll yell at you with something like fatal: Commit 148205f2fdc477ad3e4de0439d817b2a495ccf1e is a merge but no -m option was given., add -m 1 as follows instead:
    $ git cherry-pick -m1 -x 148205f2fdc477ad3e4de0439d817b2a495ccf1e
  5. At this point, you'll probably encounter some merge conflicts. You must
    resolve them in to preserve the patch from PR Add masked WebSocket read benchmarks and fix read benchmark backpressure #13561 as close to the
    original as possible.
  6. Push this branch to your fork on GitHub:
    $ git push origin patchback/backports/3.14/148205f2fdc477ad3e4de0439d817b2a495ccf1e/pr-13561
  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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-3.14 Trigger automatic backporting to the 3.14 release branch by Patchback robot backport-3.15 Trigger automatic backporting to the 3.15 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.

1 participant