Skip to content
Latchkey LogoLatchkey home

Benchmark workflow (django/django)

The Benchmark workflow from django/django, explained and optimized by Latchkey.

Source: django/django.github/workflows/benchmark.ymlLicense BSD-3-ClauseView source
A
CI health grade
84/100
Health score
1
Job per trigger
2
Fixes in the optimized version

In short

  1. CI health: A (excellent)
  2. The optimized version below points runs-on at Latchkey managed runners and adds run de-duplication.

What it does

This is the Benchmark workflow from the django/django repository, a real project running GitHub Actions. It is shown here with attribution under its BSD-3-Clause license.

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

The workflow

workflow (.yml)
name: Benchmark

on:
  pull_request:
    types: [ labeled, synchronize, opened, reopened ]

permissions:
   contents: read

jobs:
  Run_benchmarks:
    if: contains(github.event.pull_request.labels.*.name, 'benchmark')
    runs-on: ubuntu-latest
    timeout-minutes: 60
    steps:
      - name: Checkout Benchmark Repo
        uses: actions/checkout@v7
        with:
          repository: django/django-asv
          path: "."
          persist-credentials: false
      - name: Setup Miniforge
        # Pinned to v3.2.0.
        uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f
        with:
          miniforge-version: "24.1.2-0"
          activate-environment: asv-bench
      - name: Install Requirements
        run: pip install -r requirements.txt
      - name: Cache Django
        uses: actions/cache@v6
        with:
          path: Django/*
          key: Django
      - name: Run Benchmarks
        shell: bash -l {0}
        run: |-
          asv machine --machine ubuntu-latest --yes > /dev/null
          echo 'Beginning benchmarks...'
          asv continuous --interleave-processes -a processes=2 --split --show-stderr 'HEAD^' 'HEAD' |\
          sed -n -E '/(before.*after.*ratio)|(BENCHMARKS)/,$p' >> out.txt
          echo 'Benchmarks Done.'
          echo '```' >> $GITHUB_STEP_SUMMARY
          cat out.txt >> $GITHUB_STEP_SUMMARY
          echo '```' >> $GITHUB_STEP_SUMMARY
          if grep -q "PERFORMANCE DECREASED" out.txt;
          then
            exit 1
          fi

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

workflow (.yml), optimized
name: Benchmark

on:
  pull_request:
    types: [ labeled, synchronize, opened, reopened ]

permissions:
   contents: read

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  Run_benchmarks:
    if: contains(github.event.pull_request.labels.*.name, 'benchmark')
    runs-on: ubuntu-latest
    runs-on: latchkey-small
    timeout-minutes: 60
    steps:
      - name: Checkout Benchmark Repo
        uses: actions/checkout@v7
        with:
          repository: django/django-asv
          path: "."
          persist-credentials: false
      - name: Setup Miniforge
        # Pinned to v3.2.0.
        uses: conda-incubator/setup-miniconda@835234971496cad1653abb28a638a281cf32541f
        with:
          miniforge-version: "24.1.2-0"
          activate-environment: asv-bench
      - name: Install Requirements
        run: pip install -r requirements.txt
      - name: Cache Django
        uses: actions/cache@v6
        with:
          path: Django/*
          key: Django
      - name: Run Benchmarks
        shell: bash -l {0}
        run: |-
          asv machine --machine ubuntu-latest --yes > /dev/null
          echo 'Beginning benchmarks...'
          asv continuous --interleave-processes -a processes=2 --split --show-stderr 'HEAD^' 'HEAD' |\
          sed -n -E '/(before.*after.*ratio)|(BENCHMARKS)/,$p' >> out.txt
          echo 'Benchmarks Done.'
          echo '```' >> $GITHUB_STEP_SUMMARY
          cat out.txt >> $GITHUB_STEP_SUMMARY
          echo '```' >> $GITHUB_STEP_SUMMARY
          if grep -q "PERFORMANCE DECREASED" out.txt;
          then
            exit 1
          fi

What changed

  1. Run on Latchkey managed runners with one line (runs-on), which apply the fixes below automatically and self-heal transient failures. Each Linux x64 job moves to the Latchkey size matching its vCPU count, latchkey-small for a standard 2 vCPU runner; macOS, Windows and arm64 jobs stay as written.
  2. Cancel superseded runs when a branch or PR gets a newer push.

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:

  • Dependency installs

This workflow runs 1 job per trigger. It runs on a standard GitHub-hosted Linux x64 runner, which in a private repository bills $0.006 a minute against $0.0025 on latchkey-small, 58% lower; in a public repository like this one it is free. Estimate the monthly difference with your own run counts.

Actions used in this workflow

  • actions/checkout
  • conda-incubator/setup-miniconda
  • actions/cache

Frequently asked questions

What does the Benchmark workflow (django/django) workflow do?
This is the Benchmark workflow from the django/django repository, a real project running GitHub Actions. It is shown here with attribution under its BSD-3-Clause license.
What CI health grade does this workflow get?
This Automation and other workflow grades A. Paste your own workflow into the Latchkey grader to see its grade and the exact fixes.
How can I improve this Automation and other workflow?
Add run de-duplication. Latchkey applies these automatically on managed runners when you point runs-on at Latchkey.

References