Skip to content

Conversation

@pull
Copy link

@pull pull bot commented Mar 30, 2025

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.1)

Can you help keep this open source service alive? 💖 Please sponsor : )

layday and others added 5 commits March 30, 2025 21:31
Improve performance of serializing headers by moving the check for `\r`
and `\n` into the write loop instead of making a separate call to check
each disallowed character in the Python string.
<!-- Thank you for your contribution! -->

## What do these changes do?

Use a `const unsigned char *` for the buffer (Cython will automatically
extract is using `__Pyx_PyBytes_AsUString`) as its a lot faster than
copying around `PyBytes` objects. We do need to be careful that all
slices are bounded and we bound check everything to make sure we do not
do an out of bounds read since Cython does not bounds check C strings.

I checked that all accesses to `buf_cstr` are proceeded by a bounds
check but it would be good to get another set of eyes on that to verify
in the `self._state == READ_PAYLOAD` block that we will never try to
read out of bounds.

<img width="376" alt="Screenshot 2025-03-19 at 10 21 54 AM"
src="https://github.com/user-attachments/assets/a340ffa2-f09b-4aff-a4f7-c487dae186c8"
/>




## Are there changes in behavior for the user?

performance improvement

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

no

There is a small risk that someone could remove a bounds check in the
future and create a memory safety issue, however in this case its likely
we would already be trying to read data that wasn't there if we are
missing the bounds checking so the pure python version would throw if we
are testing properly.

---------

Co-authored-by: Sam Bull <git@sambull.org>
@pull pull bot added the ⤵️ pull label Mar 30, 2025
@pull pull bot merged commit caa5792 into tj-python:master Mar 30, 2025
@codecov-commenter
Copy link

codecov-commenter commented Mar 30, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.70%. Comparing base (e66b5fe) to head (caa5792).
Report is 5 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #183   +/-   ##
=======================================
  Coverage   98.70%   98.70%           
=======================================
  Files         125      125           
  Lines       37368    37378   +10     
  Branches     2064     2064           
=======================================
+ Hits        36883    36893   +10     
  Misses        338      338           
  Partials      147      147           
Flag Coverage Δ
CI-GHA 98.58% <100.00%> (+<0.01%) ⬆️
OS-Linux 98.24% <100.00%> (+<0.01%) ⬆️
OS-Windows 96.19% <57.69%> (-0.01%) ⬇️
OS-macOS 97.36% <61.53%> (-0.01%) ⬇️
Py-3.10.11 97.27% <61.53%> (-0.01%) ⬇️
Py-3.10.16 97.81% <100.00%> (+<0.01%) ⬆️
Py-3.11.11 97.89% <100.00%> (+<0.01%) ⬆️
Py-3.11.9 97.36% <61.53%> (+<0.01%) ⬆️
Py-3.12.9 98.35% <100.00%> (+<0.01%) ⬆️
Py-3.13.2 98.34% <100.00%> (+<0.01%) ⬆️
Py-3.9.13 97.14% <57.69%> (-0.02%) ⬇️
Py-3.9.21 97.68% <96.15%> (-0.01%) ⬇️
Py-pypy7.3.16 86.78% <92.30%> (+1.13%) ⬆️
VM-macos 97.36% <61.53%> (-0.01%) ⬇️
VM-ubuntu 98.24% <100.00%> (+<0.01%) ⬆️
VM-windows 96.19% <57.69%> (-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.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants