_futures.py possible performance improvement #30
Replies: 5 comments
-
|
I'm pretty sure that with this improvement you can beat uvicorn in CPython Current performance from https://www.techempower.com/benchmarks/#section=test&runid=7ce481b2-49ec-4a4d-952d-bb1334d4a4ad&test=plaintext&l=hra0hr-35r: uvicorn | 334,110 even a 5% increase will get you 338k (a little edge) to 386k (in the best scenario) Great job optimizing ASGI by the way. |
Beta Was this translation helpful? Give feedback.
-
|
Testing locally with I got 85k before and after I got 100k req/s ~17% (between 5 to 20% like I said) |
Beta Was this translation helpful? Give feedback.
-
|
@gi0baro really happy to see the last update on benchmarks and see granian ASGI winning over uvicorn http-tools 🚀 ❤️ |
Beta Was this translation helpful? Give feedback.
-
|
@gi0baro I currently create a custom Task with I will commit today, is pure Python and perform 10% to 30% better then the default Task for CPython and PyPy, with little to no code this can gives Granian another impressive performance boost, I will do some benchmarks and create an PR |
Beta Was this translation helpful? Give feedback.
-
|
@gi0baro #63 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
@gi0baro taking a loop on _future.py In:
https://github.com/emmett-framework/granian/blob/master/granian/_futures.py
the code is :
In my tests add_done_callback is really slow, in socketify I change it to do something like this:
for PyPy I used a custom task in Pure python (PyPy optimizes a lot of pure Python code) and added a task factory, to reuse tasks instead of GC and create new ones every time.
In CPython I did not use the factory strategy because pure python is slower than the built-in, but I will move to the same strategy after migrating to HPy. I believe that you can create a custom task (like I did) but make use of PyO3 to optimize to CPython and use pure Python for PyPy.
You can see my code (that needs a refactor lol) here: https://github.com/cirospaciari/socketify.py/blob/main/src/socketify/loop.py
PS: this boosted the performance on CPython for socketify by 5% to 20% depending on the test and for PyPy boost up to 50%
Comparing using TechEmPower:
Before:
falcon [socketify.py asgi] | 286,395
falcon [socketify.py asgi pypy3] | 464,546
After:
falcon [socketify.py asgi] | 327,481
falcon [socketify.py asgi pypy3] | 622,844
Incomplete run:
https://www.techempower.com/benchmarks/#section=test&runid=9bb6e0fb-1619-447c-b5f4-572207cfbc72&test=plaintext&l=hra0hr-35r
After optimizations (complete run):
https://www.techempower.com/benchmarks/#section=test&runid=7ce481b2-49ec-4a4d-952d-bb1334d4a4ad&test=plaintext&l=hra0hr-35r
I did not open a PR because I did not know how to compile and test locally, but I'm happy to help.I open a PR #31Beta Was this translation helpful? Give feedback.
All reactions