From: Daniele Varrazzo Date: Wed, 19 Oct 2022 15:38:20 +0000 (+0100) Subject: perf: use wait_select on Windows X-Git-Tag: 3.1.5~7^2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=46b49b6f37b4144b1f5b27c4781e15986391c2e4;p=thirdparty%2Fpsycopg.git perf: use wait_select on Windows On windows, the default selector strategy is select. As a consequence using the higher level selector object comes with a performance penalty. --- diff --git a/psycopg/psycopg/waiting.py b/psycopg/psycopg/waiting.py index a784aaab4..3fb4cf097 100644 --- a/psycopg/psycopg/waiting.py +++ b/psycopg/psycopg/waiting.py @@ -214,6 +214,9 @@ async def wait_conn_async(gen: PQGenConn[RV], timeout: Optional[float] = None) - return rv +# Specialised implementation of wait functions. + + def wait_select(gen: PQGen[RV], fileno: int, timeout: Optional[float] = None) -> RV: """ Wait for a generator using select where supported. @@ -297,7 +300,16 @@ def wait_epoll(gen: PQGen[RV], fileno: int, timeout: Optional[float] = None) -> return rv -if selectors.DefaultSelector is getattr(selectors, "EpollSelector", None): +# Choose the best wait strategy for the platform. +# +# the selectors objects have a generic interface but come with some overhead, +# so we also offer more finely tuned implementations. + +if selectors.DefaultSelector is getattr(selectors, "SelectSelector", None): + # On Windows, SelectSelector should be the default. + wait = wait_select + +elif selectors.DefaultSelector is getattr(selectors, "EpollSelector", None): # NOTE: select seems more performing than epoll. It is admittedly unlikely # that a platform has epoll but not select, so maybe we could kill # wait_epoll altogether(). More testing to do.