Skip to content

build: Added build support for jemalloc.#315

Open
pdath wants to merge 1 commit into
bitcoinknots:29.x-knotsfrom
pdath:feature-jemalloc
Open

build: Added build support for jemalloc.#315
pdath wants to merge 1 commit into
bitcoinknots:29.x-knotsfrom
pdath:feature-jemalloc

Conversation

@pdath

@pdath pdath commented Jun 21, 2026

Copy link
Copy Markdown

Back in 2024 Bitcoin Core added support for an alternative memory allocator called jemalloc. bitcoin#25569
However, support was never added to the build environment.

This is primarily a cmake change to enable support to link in the jemalloc library, and a tiny documentation update. There are no source code changes. I have modelled this change off WITH_ZMQ. Keys steps to use jemalloc are:
sudo sudo apt install libjemalloc-dev
cmake -B build -DWITH_JEMALLOC=ON
cmake --build build

The problem I am trying to solve is how to improve the performance of Bitcoin Knots for miners. Pool's frequently exercise RPC functions that involve a lot of JSON processing, such as getblocktemplate. When I use the following benchmark:

bench_bitcoin -filter="RpcMempool" -min-time=15000

I get a 30% performance improvement when jemalloc is used. When I run the entire benchmark suite there are no performance regressions of note (two performed very slightly slower, but so little I consider it within test error margins).

You can confirm jemalloc has been built into the executables with: ldd build/bin/bitcoind | grep jemalloc
ldd build/bin/bitcoin-cli | grep jemalloc

You can enable memory allocation performance information with a command like: MALLOC_CONF="stats_print:true" bitcoind
This will cause a lot of data to be displayed after the executable exits.

I have run the following test suite on Linux, and everything passed. cd ~/bitcoin/build
ctest --output-on-failure

Back in 2024 Bitcoin Core added support for an alternative memory allocator called jemalloc.
bitcoin#25569
However, support was never added to the build environment.

This is primarily a cmake change to enable support to link in the jemalloc library, and a tiny documentation update.  There are no source code changes.  I have modelled this change off WITH_ZMQ.
Keys steps to use jemalloc are:
sudo sudo apt install libjemalloc-dev
cmake -B build -DWITH_JEMALLOC=ON
cmake --build build

The problem I am trying to solve is how to improve the performance of Bitcoin Knots for miners.
Pool's frequently exercise RPC functions that involve a lot of JSON processing, such as getblocktemplate.  When I use the following benchmark:

bench_bitcoin -filter="RpcMempool" -min-time=15000

I get a 30% performance improvement when jemalloc is used.  When I run the entire benchmark suite there are no performance regressions of note (two performed very slightly slower, but so little I consider it within test error margins).

You can confirm jemalloc has been built into the executables with:
ldd build/bin/bitcoind | grep jemalloc
ldd build/bin/bitcoin-cli | grep jemalloc

You can enable memory allocation performance information with a command like:
MALLOC_CONF="stats_print:true" bitcoind
This will cause a lot of data to be displayed after the executable exits.

I have run the following test suite on Linux, and everything passed.
cd ~/bitcoin/build
ctest --output-on-failure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants