build: Added build support for jemalloc.#315
Open
pdath wants to merge 1 commit into
Open
Conversation
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
Ari4ka
approved these changes
Jun 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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