From: jerch (@jerch) <noreply+jerch@github.com>
To: psycopg/psycopg <noreply+psycopg-psycopg@github.com>
Subject: Re: [psycopg/psycopg] issue #1157: proposal: retrieve range value dumper from inner_oid setting
Date: Tue, 21 Oct 2025 11:58:44 +0000
Message-ID: <gh-psycopg-psycopg-1157-c3426237382@github.com> (raw)
In-Reply-To: <gh-psycopg-psycopg-1157@github.com>
References: <gh-psycopg-psycopg-1157@github.com>
The following is now implemented for range types:
- binary dumpers --> huge benefit being ~4x faster
- text dumpers --> small benefit being ~2x faster
- binary loaders --> tiny benefit being ~1.3x faster
For the text dumpers it was clear, that it cannot benefit alot, as additional scans are needed for proper escaping. This is done with regexp in python, which is known to be relatively fast.
The binary loaders suffer from the ctor call into python to create the range object, which dominates the value loading. Trying to move the range construction to cython looks rather futile to me, as the range class is quite spicy in its setup. So I think there is not more to gain here (beside micro-opts in the cython code).
Only missing piece would be the text loaders, but they are even worse in regexp usage than the text dumpers, so I am currently not keen to try a cython replacement with lengthy manual content evaluation.
Next step would be to add extensive tests. I also found a few incongruent code paths between binary and text, which might need careful evaluation which one is the right way to handle things.