From dadbc6211aa6f182d9e4219c87a31dc61321bbbf Mon Sep 17 00:00:00 2001 From: messense Date: Tue, 4 Jul 2023 09:13:46 +0000 Subject: [PATCH 1/2] Always build PGO using `RUSTFLAGS` There are many ways to pass flags to rustc: * `cargo rustc`, which only affects your crate and not its dependencies. * `RUSTFLAGS` environment variable, which affects dependencies as well. See https://stackoverflow.com/a/38040431 In this case I think `RUSTFLAGS` is a better choice. --- .github/workflows/ci.yml | 9 +++++---- .github/workflows/codspeed.yml | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7b2091640..449c47fca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -454,9 +454,10 @@ jobs: --release --out pgo-wheel --interpreter ${{ matrix.maturin-interpreter || matrix.interpreter }} - -- -Cprofile-generate=${{ github.workspace }}/profdata rust-toolchain: stable docker-options: -e CI + env: + RUSTFLAGS: "-Cprofile-generate=${{ github.workspace }}/profdata" - name: detect rust host run: echo RUST_HOST=$(rustc -Vv | grep host | cut -d ' ' -f 2) >> "$GITHUB_ENV" @@ -468,10 +469,9 @@ jobs: pip install -r tests/requirements.txt pip install pydantic-core --no-index --no-deps --find-links pgo-wheel --force-reinstall pytest tests/benchmarks - rustup run stable bash -c 'echo LLVM_PROFDATA=$RUSTUP_HOME/toolchains/$RUSTUP_TOOLCHAIN/lib/rustlib/${{ env.RUST_HOST }}/bin/llvm-profdata >> "$GITHUB_ENV"' - name: merge pgo data - run: ${{ env.LLVM_PROFDATA }} merge -o ${{ github.workspace }}/merged.profdata ${{ github.workspace }}/profdata + run: rustup run stable llvm-profdata merge -o ${{ github.workspace }}/merged.profdata ${{ github.workspace }}/profdata - name: build pgo-optimized wheel uses: PyO3/maturin-action@v1 @@ -482,9 +482,10 @@ jobs: --release --out dist --interpreter ${{ matrix.maturin-interpreter || matrix.interpreter }} - -- -Cprofile-use=${{ github.workspace }}/merged.profdata rust-toolchain: stable docker-options: -e CI + env: + RUSTFLAGS: "-Cprofile-use=${{ github.workspace }}/merged.profdata" - run: ${{ matrix.ls || 'ls -lh' }} dist/ diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml index fc33ab2db..93bfdc075 100644 --- a/.github/workflows/codspeed.yml +++ b/.github/workflows/codspeed.yml @@ -62,7 +62,7 @@ jobs: run: pytest tests/benchmarks - name: Prepare merged pgo data - run: rustup run stable bash -c '$RUSTUP_HOME/toolchains/$RUSTUP_TOOLCHAIN/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata merge -o ${{ github.workspace }}/merged.profdata ${{ github.workspace }}/profdata' + run: rustup run stable llvm-profdata merge -o ${{ github.workspace }}/merged.profdata ${{ github.workspace }}/profdata - name: Compile pydantic-core for benchmarking # --no-default-features to avoid using mimalloc From aac33544d506ea068d3a5afa54442405bad34a20 Mon Sep 17 00:00:00 2001 From: messense Date: Tue, 4 Jul 2023 09:24:31 +0000 Subject: [PATCH 2/2] revert llvm-profdata change --- .github/workflows/ci.yml | 3 ++- .github/workflows/codspeed.yml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 449c47fca..2e112fbeb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -469,9 +469,10 @@ jobs: pip install -r tests/requirements.txt pip install pydantic-core --no-index --no-deps --find-links pgo-wheel --force-reinstall pytest tests/benchmarks + rustup run stable bash -c 'echo LLVM_PROFDATA=$RUSTUP_HOME/toolchains/$RUSTUP_TOOLCHAIN/lib/rustlib/${{ env.RUST_HOST }}/bin/llvm-profdata >> "$GITHUB_ENV"' - name: merge pgo data - run: rustup run stable llvm-profdata merge -o ${{ github.workspace }}/merged.profdata ${{ github.workspace }}/profdata + run: ${{ env.LLVM_PROFDATA }} merge -o ${{ github.workspace }}/merged.profdata ${{ github.workspace }}/profdata - name: build pgo-optimized wheel uses: PyO3/maturin-action@v1 diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml index 93bfdc075..fc33ab2db 100644 --- a/.github/workflows/codspeed.yml +++ b/.github/workflows/codspeed.yml @@ -62,7 +62,7 @@ jobs: run: pytest tests/benchmarks - name: Prepare merged pgo data - run: rustup run stable llvm-profdata merge -o ${{ github.workspace }}/merged.profdata ${{ github.workspace }}/profdata + run: rustup run stable bash -c '$RUSTUP_HOME/toolchains/$RUSTUP_TOOLCHAIN/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata merge -o ${{ github.workspace }}/merged.profdata ${{ github.workspace }}/profdata' - name: Compile pydantic-core for benchmarking # --no-default-features to avoid using mimalloc