chatpack 0.5.1

Prepare chat data for RAG / LLM ingestion. Supports Telegram, WhatsApp, Instagram, Discord.
Documentation
name: Benchmarks

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

permissions:
  contents: write
  pull-requests: write

env:
  CARGO_TERM_COLOR: always

jobs:
  benchmark:
    name: Performance Regression Check
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Setup Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Cache cargo
        uses: actions/cache@v4
        with:
          path: |

            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
            target/
          key: ${{ runner.os }}-cargo-bench-${{ hashFiles('**/Cargo.lock') }}

      - name: Run benchmarks
        run: cargo bench --bench parsing -- --noplot --save-baseline current

      - name: Download previous benchmark data
        uses: actions/cache@v4
        with:
          path: ./target/criterion
          key: ${{ runner.os }}-criterion-${{ github.base_ref || 'main' }}
          restore-keys: |

            ${{ runner.os }}-criterion-

      - name: Compare with baseline (PR only)
        if: github.event_name == 'pull_request'
        run: |

          if [ -d "./target/criterion" ]; then
            echo "## Benchmark Comparison" >> $GITHUB_STEP_SUMMARY
            echo "" >> $GITHUB_STEP_SUMMARY
            echo "Comparing against baseline from \`${{ github.base_ref }}\`" >> $GITHUB_STEP_SUMMARY
            echo "" >> $GITHUB_STEP_SUMMARY
            
            # Run comparison
            cargo bench --bench parsing -- --noplot --baseline main 2>&1 | tee bench_output.txt || true
            
            # Extract regression info
            if grep -q "regressed" bench_output.txt; then
              echo "### ⚠️ Performance Regressions Detected" >> $GITHUB_STEP_SUMMARY
              echo "" >> $GITHUB_STEP_SUMMARY
              echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
              grep -A 2 "regressed" bench_output.txt >> $GITHUB_STEP_SUMMARY || true
              echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
            else
              echo "### ✅ No Performance Regressions" >> $GITHUB_STEP_SUMMARY
            fi
          fi

      - name: Save benchmark baseline (main only)
        if: github.ref == 'refs/heads/main'
        run: |

          cargo bench --bench parsing -- --noplot --save-baseline main

      - name: Upload benchmark results
        uses: actions/upload-artifact@v4
        with:
          name: benchmark-results
          path: target/criterion
          retention-days: 30

  # Optional: Track benchmarks over time with GitHub Pages
  benchmark-report:
    name: Publish Benchmark Report
    runs-on: ubuntu-latest
    needs: benchmark
    if: github.ref == 'refs/heads/main'

    steps:
      - uses: actions/checkout@v4

      - name: Download benchmark results
        uses: actions/download-artifact@v4
        with:
          name: benchmark-results
          path: target/criterion

      - name: Setup Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Generate HTML report
        run: |

          cargo bench --bench parsing -- --noplot
          mkdir -p ./bench-report
          cp -r target/criterion/* ./bench-report/ || true

      - name: Deploy to GitHub Pages
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./bench-report
          destination_dir: benchmarks
          keep_files: true