Message-ID: From: "apgrucza (@apgrucza)" To: "postgresql-interfaces/psqlodbc" Date: Wed, 06 Mar 2024 00:37:41 +0000 Subject: [postgresql-interfaces/psqlodbc] PR #6: Use mimalloc to improve performance and reduce memory allocation lock contention List-Id: X-GitHub-Author-Id: 46910040 X-GitHub-Author-Login: apgrucza X-GitHub-Issue: 6 X-GitHub-Repo: postgresql-interfaces/psqlodbc X-GitHub-State: merged X-GitHub-Type: pull_request X-GitHub-Url: https://github.com/postgresql-interfaces/psqlodbc/pull/6 Content-Type: text/plain; charset=utf-8 We have a multi-threaded Windows application that was experiencing delays due to high lock contention in memory allocations from the PostgreSQL ODBC driver. We tried modifying the driver to use [mimalloc](https://github.com/microsoft/mimalloc), which is a memory allocator with better performance characteristics. After deploying this change, the delays due to lock contention disappeared. It has been running on thousands of our production deployments for 9 months without issue. I've created this pull request so that others can benefit from this change by building the driver with the `_MIMALLOC_` symbol defined and linking to the mimalloc library. If building on Windows, `BuildAll.ps1` accepts a `-UseMimalloc` argument that does this for you (requires a toolset of `v141`, `v142` or later). Below is an example of how to build with mimalloc on Windows: ``` .\BuildAll.ps1 -Platform x64 -Toolset v141 -UseMimalloc ``` Currently the usage of mimalloc is off by default, but I'd like to get people's thoughts on whether it should be enabled by default.