<div dir="ltr">I just fixed a fairly serious performance problem with postgresql-libpq&#39;s binding to PQescapeStringConn;   in was exhibiting a non-linear slowdown when more strings are escaped and retained.  <div><br></div>
<div><a href="https://github.com/lpsmith/postgresql-libpq/commit/adf32ff26cdeca0a12fa59653b49c87198acc9ae">https://github.com/lpsmith/postgresql-libpq/commit/adf32ff26cdeca0a12fa59653b49c87198acc9ae</a><br><div><br></div>
<div>If you are using postgresql-libpq&#39;s escapeStringConn,  or a library that uses it (e.g.  postgresql-simple,  or persistent-postgresql),  I do recommend upgrading.   You may or may not see a performance improvement,  depending on your particular use case,   but if you do it can be quite substantial.</div>
<div><br></div><div>It&#39;s not entirely clear to me what the root cause really is,  but it certainly appears as though it&#39;s related to the (direct) use of mallocBytes,   which was replaced with (indirect) calls to mallocForeignPtrBytes / mallocPlainForeignPtrBytes (through the bytestring package).   In this case,  it resulted in an asymptotic improvement in time complexity of some algorithms.</div>
</div><div><br></div><div>Best,<br>Leon</div></div>