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

Avoid memory copy in the WebSocket reader for small payloads #9649

Merged
merged 10 commits into from
Nov 3, 2024

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Nov 3, 2024

Only convert to bytearray when we know we are going to append messages or unmask. If the message comes in without being fragmented, we can avoid many conversions from bytes to bytearray which is the common case for small messages

@bdraco bdraco added backport-3.10 backport-3.11 Trigger automatic backporting to the 3.11 release branch by Patchback robot labels Nov 3, 2024
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Nov 3, 2024
Copy link

codspeed-hq bot commented Nov 3, 2024

CodSpeed Performance Report

Merging #9649 will improve performances by 41.4%

Comparing memcpy_websocket_reader (57649f7) with master (541b149)

Summary

⚡ 2 improvements
✅ 9 untouched benchmarks

Benchmarks breakdown

Benchmark master memcpy_websocket_reader Change
test_one_thousand_large_round_trip_websocket_text_messages[pyloop] 32.6 ms 23 ms +41.4%
test_read_one_hundred_websocket_text_messages[pyloop] 470.1 µs 351.1 µs +33.88%

@bdraco bdraco marked this pull request as ready for review November 3, 2024 09:30
@bdraco bdraco merged commit f2f5b05 into master Nov 3, 2024
41 of 42 checks passed
@bdraco bdraco deleted the memcpy_websocket_reader branch November 3, 2024 09:39
Copy link
Contributor

patchback bot commented Nov 3, 2024

Backport to 3.11: 💚 backport PR created

✅ Backport PR branch: patchback/backports/3.11/f2f5b056e895e11eddd054132a20f83d2d6a7a07/pr-9649

Backported as #9650

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

@bdraco
Copy link
Member Author

bdraco commented Nov 3, 2024

websocket

@bdraco
Copy link
Member Author

bdraco commented Nov 3, 2024

Screenshot 2024-11-03 at 3 44 15 AM

Less time spent parsing now than the receive and DataQueue calls

Copy link

codecov bot commented Nov 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.64%. Comparing base (541b149) to head (57649f7).
Report is 1 commits behind head on master.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9649   +/-   ##
=======================================
  Coverage   98.64%   98.64%           
=======================================
  Files         115      115           
  Lines       35417    35437   +20     
  Branches     4199     4203    +4     
=======================================
+ Hits        34938    34958   +20     
  Misses        321      321           
  Partials      158      158           
Flag Coverage Δ
CI-GHA 98.53% <100.00%> (+<0.01%) ⬆️
OS-Linux 98.20% <100.00%> (+<0.01%) ⬆️
OS-Windows 96.09% <34.37%> (-0.03%) ⬇️
OS-macOS 97.40% <34.37%> (-0.03%) ⬇️
Py-3.10.11 97.25% <34.37%> (-0.03%) ⬇️
Py-3.10.15 97.68% <100.00%> (+<0.01%) ⬆️
Py-3.11.10 97.75% <100.00%> (-0.01%) ⬇️
Py-3.11.9 97.33% <34.37%> (-0.03%) ⬇️
Py-3.12.7 98.23% <100.00%> (+<0.01%) ⬆️
Py-3.13.0 98.22% <100.00%> (+<0.01%) ⬆️
Py-3.9.13 97.17% <34.37%> (-0.03%) ⬇️
Py-3.9.20 97.59% <100.00%> (+<0.01%) ⬆️
Py-pypy7.3.16 97.21% <100.00%> (+<0.01%) ⬆️
VM-macos 97.40% <34.37%> (-0.03%) ⬇️
VM-ubuntu 98.20% <100.00%> (+<0.01%) ⬆️
VM-windows 96.09% <34.37%> (-0.03%) ⬇️

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.

bdraco added a commit that referenced this pull request Nov 3, 2024
… reader for small payloads (#9650)

**This is a backport of PR #9649 as merged into master
(f2f5b05).**

Only convert to `bytearray` when we know we are going to append messages
or unmask. If the message comes in without being fragmented, we can
avoid many conversions from `bytes` to `bytearray` which is the common
case for small messages

Co-authored-by: J. Nick Koston <[email protected]>
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 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