Interestingly, the native Python Postgres driver “Asyncpg” is faster than psycopg which is writhe in C.
asyncpg has these two C files and also uses Cython as far as I can see.
https://github.com/MagicStack/asyncpg/blob/master/asyncpg/pr...
https://github.com/MagicStack/asyncpg/blob/master/asyncpg/pr...
If you are interested here is a post by the psycopg author about psycopg2 and 3 and performance versus asyncpg.
https://www.varrazzo.com/blog/2020/05/19/a-trip-into-optimis...