sanic-org/sanic
The AsyncIO Server should use Python's 3.7 BufferedProtocol when possible ?
Open
#1,873 opened on Jun 15, 2020
feature requesthelp wantedidea discussionneeds investigation
Repository metrics
- Stars
- (17,623 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
Not sure how much performance it can add, but might be worth exploring: https://bugs.python.org/issue32251
It can be done in a backward compatible way with Python 3.6 like this: https://github.com/huge-success/sanic/blob/bedf68a9b2025618a94cb8044f495a0abd87a134/sanic/server.py#L47
Instead of inheriting asyncio.Protocol, it can be done:
try:
from asyncio import BufferedProtocol as BaseProtocol
# Python 3.6 support
except ImportError:
from asyncio import Protocol as BaseProtocol
And inside the implementation, it can be written for both Python 3.6 and 3.7+ by defining the 3 methods (where the first 2 use a preallocated buffer):
class HttpProtocol(BaseProtocol):
def get_buffer(self, sizehint):
def buffer_updated(self, nbytes):
# Python 3.6 support
def data_received(self, data):