MagicStack / uvloop

Ultra fast asyncio event loop.
Apache License 2.0
10.45k stars 548 forks source link

Improve SSL performance by calling SSLProtocol methods directly, not through the python's vectorcall interface #626

Open tarasko opened 2 months ago

tarasko commented 2 months ago

After profiling my app with perf I identified a couple of things that make SSLProtocol a little bit faster:

Before:

--42.75%--__pyx_f_6uvloop_4loop___uv_stream_buffered_on_read
       |          
        --42.19%--__pyx_f_6uvloop_4loop_run_in_context1
                  |          
                   --41.92%--cfunction_vectorcall_FASTCALL_KEYWORDS
                             context_run
                             |          
                              --41.83%--_PyObject_VectorcallTstate.lto_priv.18
                                        |          
                                         --41.73%--method_vectorcall
                                                   |          
                                                    --41.32%--__pyx_pw_6uvloop_4loop_11SSLProtocol_15buffer_updated

--2.51%--__pyx_f_6uvloop_4loop___uv_stream_buffered_alloc
       |          
        --1.40%--__pyx_f_6uvloop_4loop_run_in_context1
                  |          
                   --0.67%--cfunction_vectorcall_FASTCALL_KEYWORDS
                             context_run

After:

--43.18%--__pyx_f_6uvloop_4loop___uv_stream_buffered_on_read
       |          
        --42.57%--__pyx_f_6uvloop_4loop_11SSLProtocol_buffer_updated_impl

--0.79%--__pyx_f_6uvloop_4loop___uv_stream_buffered_alloc
       |          
        --0.60%--PyGILState_Ensure