Skip to content

Transform http-parser and http-writer with the new Multidict-CAPI (Currently a draft / Vizonex's Playground / Sandbox) #11320

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

Draft
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

Vizonex
Copy link
Contributor

@Vizonex Vizonex commented Jul 18, 2025

What do these changes do?

This currently is my playground of new things that is planned for multidict 6.7 which I was involved in helping write to hopefully optimize the _http_parser and _http_writer. I loved working with the llhttp http parser myself personally and seeing my work start to merge with it is nothing short of extortionary. This is not only an historical moment but could be final optimizations and benchmarks we were looking for. I wanted to spend my summer doing ethical things with my time and it seems I have hit my goals. Never thought this would be the endgame.

For right now I have hacked in a cython file that I currently am autogenerating with libclang. I left a copy in there so you can use it and not have to download the clang.dll stuff. I saved you from needing that.

Currently waiting on 6.7 to come out and with my cython portions still requiring review this will by no means take a while. I have written some notes that label and warn that these could be all held subject to change.

Edit: I have pointed everything to the multidict fork so no need to do any crazy setups.

vs-code extensions like cyright should be able to properly display what exists. If none of the cpython or libc data exists pip installing cython should do the trick.

Know that my parts and changes will not compile yet, I am waiting for multidict 6.7 to release first however but I am certain that I did the _http_writer parts correctly.

To simplify this excitement for those not wishing to read the importance of this pull request it is simply me waiting for the Multidict-CAPI and having http_writer and http_parser utilize it in cython as the final major performance optimizations.

Are there changes in behavior for the user?

It mainly involves internal refactoring however users should see at least some performance boosts when were done here. We should be able to remain on par with curl-cffi in speed if everything is done correctly, this is my agenda and goal of this pull request.

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

With all the steps I explained above this should not be a burden as this has all currently been carefully crafted and planned for the final product.

Related issue number

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • 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.

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Jul 18, 2025
Copy link

codspeed-hq bot commented Jul 18, 2025

CodSpeed Performance Report

Merging #11320 will improve performances by 37.39%

Comparing Vizonex:Vizonex-playground-multidict-capi (610eec7) with master (8afdc4d)

Summary

⚡ 1 improvements
✅ 58 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
test_serialize_headers 856.9 µs 623.7 µs +37.39%

Copy link

codecov bot commented Jul 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.76%. Comparing base (ebf65d9) to head (a7190b0).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #11320   +/-   ##
=======================================
  Coverage   98.76%   98.76%           
=======================================
  Files         129      129           
  Lines       43374    43375    +1     
  Branches     2323     2323           
=======================================
+ Hits        42837    42838    +1     
  Misses        383      383           
  Partials      154      154           
Flag Coverage Δ
CI-GHA 98.64% <100.00%> (+<0.01%) ⬆️
OS-Linux 98.38% <100.00%> (+<0.01%) ⬆️
OS-Windows 96.80% <100.00%> (-0.01%) ⬇️
OS-macOS 97.68% <100.00%> (+<0.01%) ⬆️
Py-3.10.11 97.33% <100.00%> (+<0.01%) ⬆️
Py-3.10.18 97.73% <100.00%> (+<0.01%) ⬆️
Py-3.11.13 97.92% <100.00%> (+<0.01%) ⬆️
Py-3.11.9 97.52% <100.00%> (+<0.01%) ⬆️
Py-3.12.10 97.62% <100.00%> (-0.02%) ⬇️
Py-3.12.11 98.02% <100.00%> (+<0.01%) ⬆️
Py-3.13.3 98.28% <100.00%> (+<0.01%) ⬆️
Py-3.9.13 97.21% <100.00%> (+<0.01%) ⬆️
Py-3.9.23 97.61% <100.00%> (-0.01%) ⬇️
Py-pypy7.3.16 88.53% <100.00%> (+2.00%) ⬆️
VM-macos 97.68% <100.00%> (+<0.01%) ⬆️
VM-ubuntu 98.38% <100.00%> (+<0.01%) ⬆️
VM-windows 96.80% <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.

@Vizonex
Copy link
Contributor Author

Vizonex commented Jul 18, 2025

CodSpeed Performance Report

Merging #11320 will improve performances by 34.99%

Comparing Vizonex:Vizonex-playground-multidict-capi (4103a7a) with master (815901f)1

Summary

⚡ 1 improvements ✅ 58 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
test_serialize_headers 849.4 µs 629.2 µs +34.99%

This was the benchmark I was looking for...

@bdraco
Copy link
Member

bdraco commented Jul 19, 2025

Speed up looks real 👍

@Vizonex
Copy link
Contributor Author

Vizonex commented Jul 19, 2025

Speed up looks real 👍

@bdraco Thanks :) , Seems my hard work on multidict paid off. Even with writing a seperate tool that used libclang to make the __init__.pxd file. Guess I will just have to wait for the 6.7 release so I can swap to it. The only thing missing from the _http_parser.pyx module is The Raw Request and Raw Response Objects. The test code makes figuring out how these objects work very vauge to me. We have to figure out how to setup CIMultiDictProxy but that will be it for now.

…oxy to more arguments instead of object type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

2 participants