Skip to content

Catch panics and guard null pointers across vortex-ffi #22122

Catch panics and guard null pointers across vortex-ffi

Catch panics and guard null pointers across vortex-ffi #22122

Workflow file for this run

name: Codspeed Benchmarking
# Concurrency control:
# - PRs: new commits on a feature branch will cancel in-progress (outdated) runs.
# - Push to develop: every commit gets its own group, so baseline runs never cancel and never
# queue behind each other. Serialising them meant a burst of merges left later commits without
# a finished baseline, so CodSpeed fell back to an older comparison base and reported changes
# unrelated to the PR being tested.
# - `workflow_dispatch`: groups by branch and queues if run on develop.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name == 'push' && github.sha || '' }}
cancel-in-progress: ${{ github.ref != 'refs/heads/develop' }}
on:
push:
branches: [develop]
pull_request:
types: [opened, reopened, synchronize, ready_for_review]
workflow_dispatch: { }
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
NIGHTLY_TOOLCHAIN: nightly-2026-11-13
jobs:
changes:
name: "Detect CUDA changes"
if: github.event.pull_request.draft != true
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
pull-requests: read
outputs:
run-cuda-benchmarks: ${{ github.event_name != 'pull_request' || steps.filter.outputs.cuda == 'true' }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4
id: filter
if: github.event_name == 'pull_request'
with:
filters: |
cuda:
- "vortex-cuda/**"
# Only this workflow defines the CUDA benchmark jobs.
- ".github/workflows/codspeed.yml"
# CodSpeed rejects an upload with too many benchmarks, so the simulation benchmarks run in
# shards of at most 800. The planner balances recorded target runtimes across the available
# slots, keeping allocation modes separate. It reads only manifests and committed estimates.
plan-codspeed:
name: "Plan Codspeed shards"
if: github.event.pull_request.draft != true
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
active: ${{ steps.plan.outputs.active }}
shards: ${{ steps.plan.outputs.shards }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- id: plan
run: python3 scripts/codspeed_shards.py plan >> "$GITHUB_OUTPUT"
bench-codspeed:
needs: [plan-codspeed]
strategy:
matrix:
# Fixed slots, so that each one can be a required check. The plan fills as many as it
# needs; an unused slot runs no steps and succeeds. Keep in sync with MAX_SHARDS in
# scripts/codspeed_shards.py.
shard: [1, 2, 3, 4, 5]
name: "Benchmark with Codspeed (Shard ${{ matrix.shard }})"
timeout-minutes: 60
env:
SHARD_ACTIVE: ${{ contains(fromJSON(needs.plan-codspeed.outputs.active), matrix.shard) }}
# Each CodSpeed runner is pinned to one instance type, because results depend on the CPU. An
# unused slot takes a GitHub-hosted runner instead.
runs-on: >-
${{ contains(fromJSON(needs.plan-codspeed.outputs.active), matrix.shard)
&& github.repository == 'vortex-data/vortex'
&& format('runs-on={0}/region=us-east-1/runner=amd64-codspeed-simulation/tag=bench-codspeed-{1}', github.run_id, matrix.shard)
|| 'ubuntu-latest' }}
steps:
- parallel:
- uses: runs-on/action@v2
if: env.SHARD_ACTIVE == 'true' && github.repository == 'vortex-data/vortex'
with:
sccache: s3
- name: Select shard
id: shard
env:
SHARDS: ${{ needs.plan-codspeed.outputs.shards }}
SHARD: ${{ matrix.shard }}
run: |
python3 - <<'EOF' >> "$GITHUB_OUTPUT"
import json, os
shard = json.loads(os.environ["SHARDS"]).get(os.environ["SHARD"])
if shard is None:
print("active=false")
else:
print("active=true")
print(f"build-args={shard['build-args']}")
print(f"exclude-allocations={str(shard['exclude-allocations']).lower()}")
EOF
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
if: steps.shard.outputs.active == 'true'
- uses: ./.github/actions/setup-prebuild
if: steps.shard.outputs.active == 'true'
with:
enable-sccache: ${{ github.repository == 'vortex-data/vortex' && 'true' || 'false' }}
- parallel:
- uses: ./.github/actions/system-info
if: steps.shard.outputs.active == 'true'
- name: Install Codspeed
if: steps.shard.outputs.active == 'true'
uses: taiki-e/cache-cargo-install-action@66c9585ef5ca780ee69399975a5e911f47905995
with:
tool: cargo-codspeed
# The CodSpeed action does its setup (CLI install, its Valgrind package, runner start-up)
# inside the step that runs the benchmarks, so it starts alongside the build and its
# command waits for the build to report an exit status before running anything.
- parallel:
- name: Build benchmarks
if: steps.shard.outputs.active == 'true'
env:
RUSTFLAGS: "-C target-feature=+avx2 -C force-frame-pointers=yes -C link-arg=-fuse-ld=mold"
# Benchmarks carrying `#[cpu_features]` belong to a walltime leg below and are
# skipped here. Untagged ones run as they always have, under bare names, so this
# job's CodSpeed history is unaffected.
VORTEX_BENCH_VARIANT: simulation
BUILD_STATUS: ${{ runner.temp }}/codspeed-build-status
run: |
trap 'echo $? > "$BUILD_STATUS"' EXIT
cargo codspeed build --locked ${{ steps.shard.outputs.build-args }} --profile bench
- name: Run benchmarks
if: steps.shard.outputs.active == 'true'
uses: CodSpeedHQ/action@78102a468f96d8e0ccb92d0ec49425753fc42062 # v5
env:
# codspeed-divan-compat 6 runs each benchmark in a new process by default. Simulation
# measures one iteration without warmup, so each benchmark then also pays for a cold
# allocator and cold caches. This adds about 15 µs to each benchmark and hides small
# changes in short benchmarks. Run all benchmarks of a target in one process, as before.
CODSPEED_PROCESS_ISOLATION: "false"
# Allocators return freed memory to the OS and grow their heaps with system calls. A
# system call inside a measured iteration is left out of the measure, so CodSpeed reports
# that benchmark as dominated by system calls. Keep freed memory mapped instead.
#
# mimalloc, which every benchmark binary uses, returns memory 10 ms after it is freed.
# The simulation runs many times slower than native code, so that delay can end inside a
# later benchmark's measured iteration.
MIMALLOC_PURGE_DELAY: "-1"
# glibc `malloc`, which C dependencies such as zstd use, shrinks its heap after large
# frees and grows it again with `brk`. Shrink only when 1 GiB is free at the top of the
# heap, and grow in 64 MiB steps so that a later benchmark rarely needs to grow it.
MALLOC_TRIM_THRESHOLD_: "1073741824"
MALLOC_TOP_PAD_: "67108864"
with:
run: |
BUILD_STATUS='${{ runner.temp }}/codspeed-build-status'
until [ -s "$BUILD_STATUS" ]; do sleep 2; done
if [ "$(cat "$BUILD_STATUS")" != 0 ]; then
echo "Benchmark build failed; nothing to run." >&2
exit 1
fi
cargo codspeed run
token: ${{ secrets.CODSPEED_TOKEN }}
mode: "simulation"
exclude-allocations: ${{ steps.shard.outputs.exclude-allocations }}
# Cached package restoration fails on dangling libc6-dbg documentation symlinks.
cache-instruments: "false"
bench-codspeed-python:
name: "Benchmark with Codspeed (Python)"
if: github.event.pull_request.draft != true
timeout-minutes: 45
runs-on: >-
${{ github.repository == 'vortex-data/vortex'
&& format('runs-on={0}/region=us-east-1/runner=amd64-codspeed-simulation/tag=bench-codspeed-python', github.run_id)
|| 'ubuntu-latest' }}
env:
# Same settings as the bench profile, which keeps the debug info that CodSpeed uses to
# attribute native frames. See `profile.bench_python` in Cargo.toml.
MATURIN_PEP517_ARGS: "--profile bench_python"
# pytest-codspeed records Python frames only through the CPython perf trampoline, which
# exists from Python 3.12. On the 3.11 interpreter from `.python-version`, every Python
# benchmark reported "no flamegraph". The extension is built for the stable ABI from 3.11,
# so the same build runs on 3.13.
UV_PYTHON: "3.13"
steps:
- parallel:
- uses: runs-on/action@v2
if: github.repository == 'vortex-data/vortex'
with:
sccache: s3
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- parallel:
- uses: ./.github/actions/setup-prebuild
with:
enable-sccache: ${{ github.repository == 'vortex-data/vortex' && 'true' || 'false' }}
- uses: ./.github/actions/system-info
# As in `bench-codspeed`, the CodSpeed action's setup runs alongside the build, and its
# command waits for the build to report an exit status.
- parallel:
# Build the extension before measurement, so the benchmark step does not compile it.
# Simulation runs all of the benchmark process on Valgrind, so write the input files
# first too.
- name: Build Python extension and write benchmark data
env:
VORTEX_BENCH_DATA_DIR: ${{ runner.temp }}/vortex-bench-data
BUILD_STATUS: ${{ runner.temp }}/codspeed-build-status
run: |
trap 'echo $? > "$BUILD_STATUS"' EXIT
uv sync --all-packages
cd vortex-python
uv run --all-packages --no-sync python -m benchmark.data "$VORTEX_BENCH_DATA_DIR"
- name: Run benchmarks
uses: CodSpeedHQ/action@78102a468f96d8e0ccb92d0ec49425753fc42062 # v5
env:
VORTEX_BENCH_DATA_DIR: ${{ runner.temp }}/vortex-bench-data
# Drive scans on the calling thread. Background workers wake every 100 ms to check
# for shutdown. Under simulation, those timer wakeups can dominate the measured work.
VORTEX_MAX_THREADS: "0"
with:
run: |
BUILD_STATUS='${{ runner.temp }}/codspeed-build-status'
until [ -s "$BUILD_STATUS" ]; do sleep 2; done
if [ "$(cat "$BUILD_STATUS")" != 0 ]; then
echo "Python extension build failed; nothing to run." >&2
exit 1
fi
cd vortex-python && uv run --all-packages --no-sync pytest benchmark/ --codspeed
token: ${{ secrets.CODSPEED_TOKEN }}
mode: "simulation"
# Cached package restoration fails on dangling libc6-dbg documentation symlinks.
cache-instruments: "false"
# Compile on smaller VMs from the same CPU family as the measurement hosts. Globally
# enabled features also affect build scripts, so the build host must support them.
bench-codspeed-cpu-features-build:
if: github.event.pull_request.draft != true && github.repository == 'vortex-data/vortex'
strategy:
fail-fast: false
matrix: &cpu-feature-matrix
include:
# avx2 and avx512 share a family so the only difference between the two series is
# the build flags, not the silicon. c7i.metal-24xl is the smaller of the two c7i
# metal sizes: Sapphire Rapids, and AVX-512 capable.
- features: avx2
runner: amd64-codspeed-walltime
build-runner: amd64-codspeed-build
rustflags: "-C target-feature=+avx2 -C force-frame-pointers=yes"
# Every AVX-512 extension Sapphire Rapids implements, not just the two the current
# `cfg(target_feature)` gates test for. Those gates decide which kernel the code
# under test selects, but the rest of the build — anything the compiler
# auto-vectorizes, the scalar baselines included — sees the whole feature set, and
# a two-feature build is not what anything ships on.
- features: avx512
runner: amd64-codspeed-walltime
build-runner: amd64-codspeed-build
rustflags: >-
-C target-feature=+avx512f,+avx512bw,+avx512cd,+avx512dq,+avx512vl,+avx512ifma,+avx512vbmi,+avx512vbmi2,+avx512vnni,+avx512bitalg,+avx512vpopcntdq,+avx512bf16,+avx512fp16
-C force-frame-pointers=yes
# Graviton3 supports SVE, so this family can also host a future SVE leg.
- features: neon
runner: arm64-codspeed-walltime
build-runner: arm64-codspeed-build
rustflags: "-C target-feature=+neon -C force-frame-pointers=yes"
name: "Build Codspeed CPU benchmarks (${{ matrix.features }})"
timeout-minutes: 30
runs-on: >-
runs-on=${{ github.run_id }}/region=us-east-1/runner=${{ matrix.build-runner }}/tag=bench-codspeed-cpu-features-build-${{ matrix.features }}
steps:
- parallel:
- uses: runs-on/action@v2
with:
sccache: s3
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- parallel:
- uses: ./.github/actions/setup-prebuild
with:
enable-sccache: "true"
- uses: ./.github/actions/system-info
- parallel:
- name: Install Codspeed
uses: taiki-e/cache-cargo-install-action@66c9585ef5ca780ee69399975a5e911f47905995
with:
tool: cargo-codspeed
# Select individual targets: selecting packages also links their untagged binaries,
# including nearly all of vortex-array, even though this job never measures them.
- name: Select tagged benchmark targets
id: select
run: |
python3 - <<'EOF' >> "$GITHUB_OUTPUT"
import json, pathlib, subprocess
meta = json.loads(subprocess.check_output(
["cargo", "metadata", "--locked", "--no-deps", "--format-version", "1"]))
tagged = sorted(
(package["name"], target["name"])
for package in meta["packages"]
for target in package["targets"]
if "bench" in target["kind"]
and "#[vortex_bench_support::cpu_features" in pathlib.Path(target["src_path"]).read_text()
)
if not tagged:
raise SystemExit("no benchmark carries `#[cpu_features]`; this job has nothing to measure")
print("packages=" + " ".join(f"-p {name}" for name in sorted({package for package, _ in tagged})))
print("benches=" + " ".join(f"--bench {name}" for name in sorted({bench for _, bench in tagged})))
EOF
- name: Build benchmarks
env:
RUSTFLAGS: ${{ matrix.rustflags }}
VORTEX_BENCH_VARIANT: ${{ matrix.features }}
VORTEX_BENCH_PREFIX: "${{ matrix.features }}::"
VORTEX_BENCH_SUFFIX: "_${{ matrix.features }}"
run: |
# Preserve the bench profile debug level instead of cargo-codspeed's full debug info.
export CARGO_ENCODED_RUSTFLAGS="${RUSTFLAGS// /$'\x1f'}"
cargo codspeed build --locked -m walltime --profile bench \
${{ steps.select.outputs.packages }} ${{ steps.select.outputs.benches }}
- name: Package benchmark executables
run: tar -C target -I 'zstd -T0 -3' -cf codspeed-cpu-benchmarks.tar.zst codspeed
- name: Upload benchmark executables
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: codspeed-cpu-benchmarks-${{ matrix.features }}
path: codspeed-cpu-benchmarks.tar.zst
compression-level: 0
retention-days: 1
if-no-files-found: error
# Only measurements need metal. Reuse the build matrix to keep each artifact paired
# with the matching CPU family, image, and benchmark-name filter.
bench-codspeed-cpu-features:
if: github.repository == 'vortex-data/vortex'
needs: [bench-codspeed-cpu-features-build]
strategy:
fail-fast: false
matrix: *cpu-feature-matrix
name: "Benchmark with Codspeed (${{ matrix.features }})"
timeout-minutes: 30
runs-on: >-
runs-on=${{ github.run_id }}/region=us-east-1/runner=${{ matrix.runner }}/tag=bench-codspeed-cpu-features-${{ matrix.features }}
steps:
- parallel:
# Initialise the RunsOn artifact proxy used by download-artifact.
- uses: runs-on/action@v2
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- parallel:
- uses: ./.github/actions/setup-prebuild
- uses: ./.github/actions/system-info
- name: Download benchmark executables
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
with:
name: codspeed-cpu-benchmarks-${{ matrix.features }}
- parallel:
- name: Install Codspeed
uses: taiki-e/cache-cargo-install-action@66c9585ef5ca780ee69399975a5e911f47905995
with:
tool: cargo-codspeed
# The tar archive preserves executable permissions lost by upload-artifact.
- name: Unpack benchmark executables
run: |
mkdir -p target
tar -C target --zstd -xf codspeed-cpu-benchmarks.tar.zst
# Pinning clocks and reserving CPUs only pays off for walltime measurements, so this
# runs here but not in the simulation job. It must come after setup, which itself
# spawns processes that would otherwise be pinned to the housekeeping CPUs.
- name: Setup benchmark environment
run: sudo bash scripts/setup-benchmark.sh
# The trailing filter is what keeps a leg to the tagged benchmarks. Unlike a simulation
# build, a walltime one does not set `--cfg codspeed`, so benchmarks kept out of
# CodSpeed that way are compiled in here and divan would otherwise measure them.
#
# divan matches the filter's `::`-separated components against the benchmark path's,
# so this selects paths of the form `<bench target>::<features>::<name>`. That middle
# component only exists because `#[cpu_features]` puts it there: an untagged benchmark has one
# component fewer and cannot match, whatever it is called.
- name: Run benchmarks
uses: CodSpeedHQ/action@78102a468f96d8e0ccb92d0ec49425753fc42062 # v5
env:
# Use more samples to reduce noise between walltime runs.
DIVAN_SAMPLE_COUNT: "1000"
with:
run: bash scripts/bench-taskset.sh cargo codspeed run -- '.*::${{ matrix.features }}::'
token: ${{ secrets.CODSPEED_TOKEN }}
mode: "walltime"
# Getting a GPU box is slow, in the future we can build on a box without one and only run
# on GPU machines.
bench-codspeed-cuda-build:
needs: [changes]
if: >-
!cancelled() && github.repository == 'vortex-data/vortex' &&
needs.changes.outputs.run-cuda-benchmarks == 'true'
name: "Build Codspeed CUDA benchmarks"
timeout-minutes: 30
runs-on: >-
runs-on=${{ github.run_id }}/region=us-east-1/runner=gpu-codspeed/tag=bench-codspeed-cuda-build
steps:
- parallel:
- uses: runs-on/action@v2
with:
sccache: s3
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: ./.github/actions/setup-rust
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
enable-sccache: "true"
- name: Install Codspeed
uses: taiki-e/cache-cargo-install-action@66c9585ef5ca780ee69399975a5e911f47905995
with:
tool: cargo-codspeed
- name: Build benchmarks
# cargo-codspeed forces -Cdebuginfo=2 -Cstrip=none
# https://github.com/CodSpeedHQ/codspeed-rust/issues/190
# CARGO_ENCODED_RUSTFLAGS allows us to override it since we need
# only debug = limited
env:
CARGO_ENCODED_RUSTFLAGS: "-Cforce-frame-pointers=yes"
run: |
cargo codspeed build --locked \
-m walltime \
--bench bitpacked_cuda \
--bench dynamic_dispatch_cuda \
--bench alp_cuda \
--bench alprd_cuda \
--bench date_time_parts_cuda \
--bench delta_cuda \
--bench dict_cuda \
--bench fsst_cuda \
--bench runend_cuda \
--profile bench
- name: Package CUB shared library
run: |
find target/release/build -path '*/out/libvortex_cub.so' \
-exec cp {} target/codspeed/walltime/vortex-cuda/libvortex_cub.so \;
test -f target/codspeed/walltime/vortex-cuda/libvortex_cub.so
- name: Package CUDA benchmark executables
run: tar -C target -I 'zstd -T0 -3' -cf codspeed-cuda-benchmarks.tar.zst codspeed
- name: Upload benchmark executables
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: codspeed-cuda-benchmarks
path: codspeed-cuda-benchmarks.tar.zst
compression-level: 0
retention-days: 1
if-no-files-found: error
bench-codspeed-cuda:
if: github.repository == 'vortex-data/vortex'
needs: [bench-codspeed-cuda-build]
name: "Benchmark with Codspeed (CUDA)"
timeout-minutes: 60
runs-on: >-
runs-on=${{ github.run_id }}/region=us-east-1/runner=gpu-codspeed/tag=bench-codspeed-cuda
steps:
- parallel:
- uses: runs-on/action@v2
with:
sccache: s3
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- parallel:
- uses: ./.github/actions/setup-rust
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
enable-sccache: "true"
- name: Display NVIDIA SMI details
run: |
nvidia-smi
nvidia-smi -L
nvidia-smi -q -d Memory
- name: Download benchmark executables
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
with:
name: codspeed-cuda-benchmarks
- parallel:
- name: Install Codspeed
uses: taiki-e/cache-cargo-install-action@66c9585ef5ca780ee69399975a5e911f47905995
with:
tool: cargo-codspeed
- name: Unpack CUDA benchmark executables
run: |
mkdir -p target
tar -C target --zstd -xf codspeed-cuda-benchmarks.tar.zst
- name: Restore executable permissions
run: find target/codspeed -type f -exec chmod +x {} +
- name: Run benchmarks
uses: CodSpeedHQ/action@78102a468f96d8e0ccb92d0ec49425753fc42062 # v5
env:
CARGO_MANIFEST_DIR: ${{ github.workspace }}/vortex-cuda
with:
# Name the benchmarks: the artifact directory also holds libvortex_cub.so, which a bare
# `cargo codspeed run` would try to execute as a benchmark.
run: >-
cargo codspeed run
--bench bitpacked_cuda --bench dynamic_dispatch_cuda --bench alp_cuda
--bench alprd_cuda
--bench date_time_parts_cuda --bench delta_cuda --bench dict_cuda
--bench fsst_cuda --bench runend_cuda
token: ${{ secrets.CODSPEED_TOKEN }}
mode: "walltime"