Skip to content
Latchkey

Benchmarks workflow (xarray-contrib/xarray-spatial)

The Benchmarks workflow from xarray-contrib/xarray-spatial, explained and optimized by Latchkey.

D

CI health: D - needs work

Point runs-on at Latchkey and get caching, run de-duplication, job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.

Grade your own workflow free or run it on Latchkey →
Source: xarray-contrib/xarray-spatial.github/workflows/benchmarks.ymlLicense MITView source

What it does

This is the Benchmarks workflow from the xarray-contrib/xarray-spatial repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
name: Benchmarks

on:
  pull_request:
    types: [labeled]
  push:
    branches: [main]

env:
  ASV_FACTOR: "1.2"

jobs:
  benchmarks:
    if: >
      (github.event_name == 'push') ||
      (github.event_name == 'pull_request' && github.event.label.name == 'performance')
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - uses: actions/setup-python@v5
        with:
          python-version: "3.13"

      - name: Install ASV and virtualenv
        run: pip install asv virtualenv

      - name: Configure ASV machine
        working-directory: benchmarks
        run: asv machine --yes

      - name: Run benchmarks (PR)
        if: github.event_name == 'pull_request'
        working-directory: benchmarks
        run: |
          asv continuous origin/main HEAD \
            --factor $ASV_FACTOR \
            --bench "^(Slope|Proximity|Zonal|CostDistance|Focal|Rescale|Standardize|Diffusion|Dasymetric)" \
            | tee bench_output.txt

      - name: Run benchmarks (push to main)
        if: github.event_name == 'push'
        working-directory: benchmarks
        run: |
          asv run HEAD^! \
            --bench "^(Slope|Proximity|Zonal|CostDistance|Focal|Rescale|Standardize|Diffusion|Dasymetric)" \
            | tee bench_output.txt

      - name: Check for regressions
        working-directory: benchmarks
        run: |
          if grep -q "REGRESSION" bench_output.txt; then
            echo "::error::Performance regression detected (>${ASV_FACTOR}x slower)"
            cat bench_output.txt
            exit 1
          fi

      - name: Upload benchmark results
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: benchmark-results
          path: |
            benchmarks/bench_output.txt
            benchmarks/.asv/results/

The same workflow, on Latchkey

Estimated ~20% faster on cache hits, plus fewer wasted runs and a safer supply chain. Added and changed lines are highlighted.

name: Benchmarks
 
on:
  pull_request:
    types: [labeled]
  push:
    branches: [main]
 
env:
  ASV_FACTOR: "1.2"
 
concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true
 
jobs:
  benchmarks:
    timeout-minutes: 30
    if: >
      (github.event_name == 'push') ||
      (github.event_name == 'pull_request' && github.event.label.name == 'performance')
    runs-on: latchkey-small
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
 
      - uses: actions/setup-python@v5
        with:
          cache: 'pip'
          python-version: "3.13"
 
      - name: Install ASV and virtualenv
        run: pip install asv virtualenv
 
      - name: Configure ASV machine
        working-directory: benchmarks
        run: asv machine --yes
 
      - name: Run benchmarks (PR)
        if: github.event_name == 'pull_request'
        working-directory: benchmarks
        run: |
          asv continuous origin/main HEAD \
            --factor $ASV_FACTOR \
            --bench "^(Slope|Proximity|Zonal|CostDistance|Focal|Rescale|Standardize|Diffusion|Dasymetric)" \
            | tee bench_output.txt
 
      - name: Run benchmarks (push to main)
        if: github.event_name == 'push'
        working-directory: benchmarks
        run: |
          asv run HEAD^! \
            --bench "^(Slope|Proximity|Zonal|CostDistance|Focal|Rescale|Standardize|Diffusion|Dasymetric)" \
            | tee bench_output.txt
 
      - name: Check for regressions
        working-directory: benchmarks
        run: |
          if grep -q "REGRESSION" bench_output.txt; then
            echo "::error::Performance regression detected (>${ASV_FACTOR}x slower)"
            cat bench_output.txt
            exit 1
          fi
 
      - name: Upload benchmark results
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: benchmark-results
          path: |
            benchmarks/bench_output.txt
            benchmarks/.asv/results/
 

What changed

What Latchkey heals here

This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:

This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow