Skip to content

Benchmarking automatically #795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
da5a310
Benchmarking automatically
mjp41 Aug 5, 2025
98bbcda
WIP
mjp41 Aug 5, 2025
7227e27
WIP
mjp41 Aug 5, 2025
5b786da
Add caching
mjp41 Aug 6, 2025
e6965ad
Alter connecting to image.
mjp41 Aug 6, 2025
31718db
Alter connecting to image.
mjp41 Aug 6, 2025
43b7f4e
Alter connecting to image.
mjp41 Aug 6, 2025
55fadf7
Alter connecting to image.
mjp41 Aug 6, 2025
3a8acdd
Alter connecting to image.
mjp41 Aug 6, 2025
7a709a7
Alter connecting to image.
mjp41 Aug 6, 2025
0b479c0
Alter connecting to image.
mjp41 Aug 6, 2025
5a20692
Alter connecting to image.
mjp41 Aug 6, 2025
e314c10
Investigate usage
mjp41 Aug 6, 2025
9e6b1eb
Investigate usage
mjp41 Aug 6, 2025
c933308
Investigate usage
mjp41 Aug 6, 2025
b5efe7b
Investigate usage
mjp41 Aug 6, 2025
244c079
Compacting.
mjp41 Aug 6, 2025
bfb665d
Compacting.
mjp41 Aug 6, 2025
5aff3a3
Compacting.
mjp41 Aug 6, 2025
84dd7ae
Apply suggestion from @achamayou
mjp41 Aug 6, 2025
6a28074
Adjust output for bencher.dev
mjp41 Aug 6, 2025
bee8d8d
Add script
mjp41 Aug 6, 2025
8767137
Adjust python deps
mjp41 Aug 6, 2025
fef6300
Adjust python deps
mjp41 Aug 6, 2025
c4a8d3e
Adjust python deps
mjp41 Aug 6, 2025
93ad1c7
Adjust python deps
mjp41 Aug 6, 2025
1d132ac
Fix path
mjp41 Aug 6, 2025
e7a44e5
Fix path
mjp41 Aug 6, 2025
73dee9b
Move around deps.
mjp41 Aug 6, 2025
47f46ff
Set to correct benchmarking.
mjp41 Aug 6, 2025
20a2346
Change name
mjp41 Aug 6, 2025
37d7624
Add cron
mjp41 Aug 6, 2025
c964172
Update script to handle multiple allocators
mjp41 Aug 7, 2025
d2e049a
Put output in right place.
mjp41 Aug 7, 2025
83df851
Refinements
mjp41 Aug 8, 2025
dfc8a2c
refinement
mjp41 Aug 8, 2025
f501e3f
refinement
mjp41 Aug 8, 2025
b23d006
Script is now upstreamed to benchmarks.
mjp41 Aug 8, 2025
26f44e9
Disable GWP Asan jemalloc test
mjp41 Aug 8, 2025
461c23f
Update Dockerfile
mjp41 Aug 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: snmalloc Benchmarking CI

# The following should ensure that the workflow only runs a single set of actions
# for each PR. But it will not apply this to pushes to the main branch.
concurrency:
group: benchmarking${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

# Controls when the workflow will run
on:
schedule:
- cron: "0 0 * * 1" # Runs every Monday at midnight UTC
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ main ]
pull_request:
branches: [ main ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that bit will work because the PRs won't have access to secrets? But then perhaps this is for testing on this PR?


# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
benchmark:
runs-on: [self-hosted, 1ES.Pool=snmalloc-perf]

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout
uses: actions/checkout@v3

# Setup docker buildx
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build and run benchmarks in Docker
id: docker_build
uses: docker/build-push-action@v4
with:
context: .
file: benchmark/Dockerfile
push: false
load: true
tags: snmalloc-bench
build-args: |
benchs=allt
repeats=5
cache-from: type=gha
cache-to: type=gha,mode=max

# Extracts the benchmark results from the Docker container
- name: Extract Benchmark Results
run: |
docker cp `docker run -d ${{ steps.docker_build.outputs.imageid }}`:/bencher.dev.sn.json .

# Uploads the benchmark results as an artifact
- name: Upload Benchmark Results
uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: bencher.dev.sn.json

# Upload to graphing service
- uses: bencherdev/bencher@main
- name: Upload benchmark results to Bencher
run: |
bencher run \
--project snmalloc \
--token '${{ secrets.BENCHER_DEV_API_TOKEN }}' \
--branch main \
--adapter json \
--err \
--file bencher.dev.sn.json
45 changes: 45 additions & 0 deletions benchmark/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FROM ubuntu:24.04

# Pull mimalloc-bench
RUN apt-get update && apt-get install -y --no-install-recommends git gpg ca-certificates python3-numpy
RUN git clone https://github.com/daanx/mimalloc-bench &&\
cd mimalloc-bench && \
git reset --hard a4ce904286365c7adfba54f0eea3a2df3fc95bd1

WORKDIR /mimalloc-bench
# Install dependencies
RUN ./build-bench-env.sh packages

# Tidy up apt cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Build benchmarks
RUN ./build-bench-env.sh bench

RUN ./build-bench-env.sh redis

RUN ./build-bench-env.sh rocksdb \
&& find /mimalloc-bench/extern/rocksdb-8.1.1 -name "*.o" -delete

RUN ./build-bench-env.sh lean \
&& find /mimalloc-bench/extern/lean -name "*.o" -delete

RUN echo "sn /snmalloc/build/libsnmallocshim.so" > /allocs.txt

# Build allocator
RUN mkdir -p /snmalloc
COPY . /snmalloc

RUN mkdir -p /snmalloc/build
WORKDIR /snmalloc/build
RUN cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ..
RUN ninja libsnmallocshim.so

# Run benchmarks
ARG benchs=allt
ARG repeats=1
WORKDIR /mimalloc-bench/out/bench
RUN ../../bench.sh --external=/allocs.txt $benchs -r=$repeats

WORKDIR /
RUN python3 /mimalloc-bench/scripts/bencher.dev.py /mimalloc-bench/out/bench/benchres.csv
113 changes: 60 additions & 53 deletions src/test/func/jemalloc/jemalloc.cc
Original file line number Diff line number Diff line change
@@ -1,65 +1,71 @@
#include <functional>
#include <limits.h>
#include <stdio.h>
#include <test/helpers.h>
#include <test/setup.h>
#if defined(SNMALLOC_ENABLE_GWP_ASAN_INTEGRATION)
int main()
{
return 0;
}
#else
# include <functional>
# include <limits.h>
# include <stdio.h>
# include <test/helpers.h>
# include <test/setup.h>

#define SNMALLOC_NAME_MANGLE(a) our_##a
#undef SNMALLOC_NO_REALLOCARRAY
#undef SNMALLOC_NO_REALLOCARR
#define SNMALLOC_BOOTSTRAP_ALLOCATOR
#define SNMALLOC_JEMALLOC3_EXPERIMENTAL
#define SNMALLOC_JEMALLOC_NONSTANDARD
#include <snmalloc/override/jemalloc_compat.cc>
#include <snmalloc/override/malloc.cc>
# define SNMALLOC_NAME_MANGLE(a) our_##a
# undef SNMALLOC_NO_REALLOCARRAY
# undef SNMALLOC_NO_REALLOCARR
# define SNMALLOC_BOOTSTRAP_ALLOCATOR
# define SNMALLOC_JEMALLOC3_EXPERIMENTAL
# define SNMALLOC_JEMALLOC_NONSTANDARD
# include <snmalloc/override/jemalloc_compat.cc>
# include <snmalloc/override/malloc.cc>

#if __has_include(<malloc_np.h>)
# include <malloc_np.h>
#endif
# if __has_include(<malloc_np.h>)
# include <malloc_np.h>
# endif

#ifdef __FreeBSD__
# ifdef __FreeBSD__
/**
* Enable testing against the versions that we get from libc or elsewhere.
* Enabled by default on FreeBSD where all of the jemalloc functions are
* exported from libc.
*/
# define TEST_JEMALLOC_MALLOCX
#endif
# define TEST_JEMALLOC_MALLOCX
# endif

#define OUR_MALLOCX_LG_ALIGN(la) (static_cast<int>(la))
#define OUR_MALLOCX_ZERO (one_at_bit<int>(6))
# define OUR_MALLOCX_LG_ALIGN(la) (static_cast<int>(la))
# define OUR_MALLOCX_ZERO (one_at_bit<int>(6))

#define OUR_ALLOCM_NO_MOVE (one_at_bit<int>(7))
# define OUR_ALLOCM_NO_MOVE (one_at_bit<int>(7))

#define OUR_ALLOCM_SUCCESS 0
#define OUR_ALLOCM_ERR_OOM 1
#define OUR_ALLOCM_ERR_NOT_MOVED 2
# define OUR_ALLOCM_SUCCESS 0
# define OUR_ALLOCM_ERR_OOM 1
# define OUR_ALLOCM_ERR_NOT_MOVED 2

#ifndef MALLOCX_LG_ALIGN
# define MALLOCX_LG_ALIGN(la) OUR_MALLOCX_LG_ALIGN(la)
#endif
#ifndef MALLOCX_ZERO
# define MALLOCX_ZERO OUR_MALLOCX_ZERO
#endif
# ifndef MALLOCX_LG_ALIGN
# define MALLOCX_LG_ALIGN(la) OUR_MALLOCX_LG_ALIGN(la)
# endif
# ifndef MALLOCX_ZERO
# define MALLOCX_ZERO OUR_MALLOCX_ZERO
# endif

#ifndef ALLOCM_LG_ALIGN
# define ALLOCM_LG_ALIGN(la) OUR_MALLOCX_LG_ALIGN(la)
#endif
#ifndef ALLOCM_ZERO
# define ALLOCM_ZERO OUR_MALLOCX_ZERO
#endif
#ifndef ALLOCM_NO_MOVE
# define ALLOCM_NO_MOVE OUR_ALLOCM_NO_MOVE
#endif
#ifndef ALLOCM_SUCCESS
# define ALLOCM_SUCCESS OUR_ALLOCM_SUCCESS
#endif
#ifndef ALLOCM_ERR_OOM
# define ALLOCM_ERR_OOM OUR_ALLOCM_ERR_OOM
#endif
#ifndef ALLOCM_ERR_NOT_MOVED
# define ALLOCM_ERR_NOT_MOVED OUR_ALLOCM_ERR_NOT_MOVED
#endif
# ifndef ALLOCM_LG_ALIGN
# define ALLOCM_LG_ALIGN(la) OUR_MALLOCX_LG_ALIGN(la)
# endif
# ifndef ALLOCM_ZERO
# define ALLOCM_ZERO OUR_MALLOCX_ZERO
# endif
# ifndef ALLOCM_NO_MOVE
# define ALLOCM_NO_MOVE OUR_ALLOCM_NO_MOVE
# endif
# ifndef ALLOCM_SUCCESS
# define ALLOCM_SUCCESS OUR_ALLOCM_SUCCESS
# endif
# ifndef ALLOCM_ERR_OOM
# define ALLOCM_ERR_OOM OUR_ALLOCM_ERR_OOM
# endif
# ifndef ALLOCM_ERR_NOT_MOVED
# define ALLOCM_ERR_NOT_MOVED OUR_ALLOCM_ERR_NOT_MOVED
# endif

using namespace snmalloc;
using namespace snmalloc::bits;
Expand Down Expand Up @@ -335,21 +341,22 @@ int main()
our_dallocm,
our_nallocm>();

#ifndef __PIC__
# ifndef __PIC__
void* bootstrap = __je_bootstrap_malloc(42);
if (bootstrap == nullptr)
{
printf("Failed to allocate from bootstrap malloc\n");
}
__je_bootstrap_free(bootstrap);
#endif
# endif

// These tests are for jemalloc compatibility and so should work with
// jemalloc's implementation of these functions. If TEST_JEMALLOC is
// defined then we try
#ifdef TEST_JEMALLOC_MALLOCX
# ifdef TEST_JEMALLOC_MALLOCX
test_size<mallocx, dallocx, sallocx, nallocx>();
test_zeroing<mallocx, dallocx, rallocx>();
test_xallocx<mallocx, dallocx, xallocx>();
#endif
# endif
}
#endif // SNMALLOC_ENABLE_GWP_ASAN_INTEGRATION
Loading