There are a number of ideas floating around on where and how to make Sanic faster. I want to start compiling them here.
I did some pretty crude initial testing to see where time is being spent (will try to do something more sophisticated later). Here is the results:
Timing: _run_request_middleware 6.67572021484375 Timing: self.router.get 47.92213439941406 Timing: handler 22.411346435546875 Timing: _run_response_middleware 2.86102294921875 Timing: write_callback 97.99003601074219 Timer results: _run_request_middleware: 3.75% self.router.get: 26.94% handler: 12.6% _run_response_middleware: 1.61% write_callback: 55.09%
This is on a cold start of a basic hello world app, so no
lrucache on the router and nothing complex at all. As you can see, the
write_callback takes up much of the time. This comment here, seems to imply we may have maxed out speed in “pure python”:
This is all returned in a kind-of funky way
We tried to make this as fast as possible in pure python
Maybe we need to start looking at Cython or other utilties to get some gains in the output and also the router? Initial thoughts?
What is more important? Speed or a pure Python package?
- pure Python
By “pure python” I mean using the Standard Library as used in the the versions of Python that are supported by Sanic (cPython 3.5, 3.6 and 3.7 for 18.12LTS, and 3.6, 3.7, 3.8 for 19.12LTS) as opposed to using extensions and pre-compiled code.