diff --git a/barretenberg/cpp/scripts/run_bench.sh b/barretenberg/cpp/scripts/run_bench.sh index 64df1e05eadd..205f26109569 100755 --- a/barretenberg/cpp/scripts/run_bench.sh +++ b/barretenberg/cpp/scripts/run_bench.sh @@ -14,13 +14,20 @@ filter=$4 export GTEST_COLOR=1 export HARDWARE_CONCURRENCY=${CPUS:-8} +# Set ALLOCATOR=tcmalloc to use tcmalloc via LD_PRELOAD. +BENCH_PRELOAD="" +if [ "${ALLOCATOR:-}" = "tcmalloc" ]; then + sudo apt-get update -qq && sudo apt-get install -y -qq libtcmalloc-minimal4t64 + BENCH_PRELOAD="/usr/lib/$(uname -m)-linux-gnu/libtcmalloc_minimal.so.4" +fi + mkdir -p bench-out/$(dirname $name) export MEMUSAGE_OUT="bench-out/$name-peak-memory-mb.txt" case $arch in native) - memusage $bin --benchmark_out=./bench-out/$name.json --benchmark_filter=$filter + LD_PRELOAD="${BENCH_PRELOAD}" memusage $bin --benchmark_out=./bench-out/$name.json --benchmark_filter=$filter ;; wasm) memusage ./scripts/wasmtime.sh $bin --benchmark_out=./bench-out/$name.json --benchmark_filter=$filter diff --git a/release-image/Dockerfile.base b/release-image/Dockerfile.base index 8e61fcb0babe..6ffdf0dee01e 100644 --- a/release-image/Dockerfile.base +++ b/release-image/Dockerfile.base @@ -23,7 +23,8 @@ RUN apt update && apt install -y \ netcat-openbsd \ parallel \ curl \ - gnupg && \ + gnupg \ + libtcmalloc-minimal4t64 && \ curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \ echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && \ apt update && apt install nodejs && \ @@ -33,6 +34,8 @@ COPY --from=build /opt/foundry/bin/anvil /opt/foundry/bin/anvil COPY --from=build /opt/foundry/bin/forge /opt/foundry/bin/forge COPY --from=build /opt/foundry/bin/cast /opt/foundry/bin/cast ENV PATH="/opt/foundry/bin:$PATH" FOUNDRY_DISABLE_NIGHTLY_WARNING="1" +# Use tcmalloc for reduced memory fragmentation and improved allocation performance. +ENV LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libtcmalloc_minimal.so.4" # Copy in production dependencies. COPY --from=build /usr/src/yarn-project/node_modules /usr/src/yarn-project/node_modules # We install a symlink to yarn-project's node_modules at a location that all portalled packages can find as they