If the connection is reused, we create a TimerHandler and than cancel is right away.... in testing this seems to be the case 80%+ of the time so this seem ripe to optimize away. Since we pass on the timeout object to connect anyways we could move the timeout into connect so it only does the timeout if its actually going to wait. Since we expect connection reuse to be common with HTTP/1.1+ this takes up a significant amount of the request time.
There is a small risk someone has subclassed and replaced the connect implementation with a custom connector, however it connect is quite complex so it seems unlikely someone would reimplement it. Either way it would need a breaking change note in the changelog.
aiohttp/aiohttp/client.py
Line 637 in 7d0f980
If the connection is reused, we create a TimerHandler and than cancel is right away.... in testing this seems to be the case 80%+ of the time so this seem ripe to optimize away. Since we pass on the timeout object to
connectanyways we could move the timeout intoconnectso it only does the timeout if its actually going to wait. Since we expect connection reuse to be common with HTTP/1.1+ this takes up a significant amount of the request time.There is a small risk someone has subclassed and replaced the
connectimplementation with a custom connector, however itconnectis quite complex so it seems unlikely someone would reimplement it. Either way it would need a breaking change note in the changelog.