|
| 1 | +name: Native AST Walk Perf |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - '.github/workflows/native-ast-perf.yml' |
| 7 | + - 'packages/mysql-on-sqlite/src/mysql/native/**' |
| 8 | + - 'packages/mysql-on-sqlite/tests/tools/run-native-ast-walk-benchmark.php' |
| 9 | + - 'packages/php-ext-wp-mysql-parser/**' |
| 10 | + pull_request: |
| 11 | + paths: |
| 12 | + - '.github/workflows/native-ast-perf.yml' |
| 13 | + - 'packages/mysql-on-sqlite/src/mysql/native/**' |
| 14 | + - 'packages/mysql-on-sqlite/tests/tools/run-native-ast-walk-benchmark.php' |
| 15 | + - 'packages/php-ext-wp-mysql-parser/**' |
| 16 | + workflow_dispatch: |
| 17 | + |
| 18 | +concurrency: |
| 19 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 20 | + cancel-in-progress: true |
| 21 | + |
| 22 | +jobs: |
| 23 | + perf: |
| 24 | + name: Native AST walk benchmark |
| 25 | + runs-on: ubuntu-latest |
| 26 | + timeout-minutes: 25 |
| 27 | + |
| 28 | + steps: |
| 29 | + - name: Checkout repository |
| 30 | + uses: actions/checkout@v4 |
| 31 | + |
| 32 | + - name: Set up PHP |
| 33 | + uses: shivammathur/setup-php@v2 |
| 34 | + with: |
| 35 | + php-version: '8.2' |
| 36 | + coverage: none |
| 37 | + |
| 38 | + - name: Set up Rust |
| 39 | + uses: dtolnay/rust-toolchain@stable |
| 40 | + |
| 41 | + - name: Install native build dependencies |
| 42 | + run: | |
| 43 | + sudo apt-get update |
| 44 | + sudo apt-get install -y libclang-dev |
| 45 | + echo "PHP_CONFIG=$(command -v php-config)" >> "$GITHUB_ENV" |
| 46 | + LIBCLANG_SO="$(find /usr/lib -name 'libclang.so*' | head -n 1)" |
| 47 | + echo "LIBCLANG_PATH=$(dirname "$LIBCLANG_SO")" >> "$GITHUB_ENV" |
| 48 | +
|
| 49 | + - name: Install Composer dependencies (root) |
| 50 | + uses: ramsey/composer-install@v3 |
| 51 | + with: |
| 52 | + ignore-cache: "yes" |
| 53 | + composer-options: "--optimize-autoloader" |
| 54 | + |
| 55 | + - name: Install Composer dependencies (mysql-on-sqlite) |
| 56 | + uses: ramsey/composer-install@v3 |
| 57 | + with: |
| 58 | + working-directory: packages/mysql-on-sqlite |
| 59 | + ignore-cache: "yes" |
| 60 | + composer-options: "--optimize-autoloader" |
| 61 | + |
| 62 | + - name: Download MySQL test query corpus |
| 63 | + working-directory: packages/mysql-on-sqlite |
| 64 | + run: bash tests/tools/mysql-download-tests.sh || true |
| 65 | + |
| 66 | + - name: Build parser extension (release) |
| 67 | + run: cargo build --release |
| 68 | + working-directory: packages/php-ext-wp-mysql-parser |
| 69 | + |
| 70 | + - name: Locate built extension |
| 71 | + run: | |
| 72 | + EXT="$GITHUB_WORKSPACE/packages/php-ext-wp-mysql-parser/target/release/libwp_mysql_parser.so" |
| 73 | + test -f "$EXT" || { echo "Extension not built at $EXT"; exit 1; } |
| 74 | + echo "NATIVE_EXT=$EXT" >> "$GITHUB_ENV" |
| 75 | +
|
| 76 | + - name: Benchmark — pure-PHP path (parse only) |
| 77 | + working-directory: packages/mysql-on-sqlite |
| 78 | + run: | |
| 79 | + php tests/tools/run-native-ast-walk-benchmark.php --no-walk | tee php-parse-only.txt |
| 80 | +
|
| 81 | + - name: Benchmark — pure-PHP path (walk) |
| 82 | + working-directory: packages/mysql-on-sqlite |
| 83 | + run: | |
| 84 | + php tests/tools/run-native-ast-walk-benchmark.php | tee php-walk.txt |
| 85 | +
|
| 86 | + - name: Benchmark — native path (parse only) |
| 87 | + working-directory: packages/mysql-on-sqlite |
| 88 | + run: | |
| 89 | + php -d extension="$NATIVE_EXT" tests/tools/run-native-ast-walk-benchmark.php --no-walk | tee native-parse-only.txt |
| 90 | +
|
| 91 | + - name: Benchmark — native path (walk, with identity cache) |
| 92 | + working-directory: packages/mysql-on-sqlite |
| 93 | + run: | |
| 94 | + php -d extension="$NATIVE_EXT" tests/tools/run-native-ast-walk-benchmark.php | tee native-walk.txt |
| 95 | +
|
| 96 | + - name: Check out baseline (PR base, no identity cache) |
| 97 | + run: | |
| 98 | + git fetch --no-tags --depth=1 origin codex/native-lazy-ast-facade |
| 99 | + git worktree add ../baseline FETCH_HEAD |
| 100 | +
|
| 101 | + - name: Install Composer dependencies (baseline mysql-on-sqlite) |
| 102 | + uses: ramsey/composer-install@v3 |
| 103 | + with: |
| 104 | + working-directory: ../baseline/packages/mysql-on-sqlite |
| 105 | + ignore-cache: "yes" |
| 106 | + composer-options: "--optimize-autoloader" |
| 107 | + |
| 108 | + - name: Build baseline parser extension (release) |
| 109 | + run: cargo build --release |
| 110 | + working-directory: ../baseline/packages/php-ext-wp-mysql-parser |
| 111 | + |
| 112 | + - name: Stage benchmark + corpus into baseline |
| 113 | + run: | |
| 114 | + mkdir -p ../baseline/packages/mysql-on-sqlite/tests/mysql/data |
| 115 | + cp packages/mysql-on-sqlite/tests/tools/run-native-ast-walk-benchmark.php \ |
| 116 | + ../baseline/packages/mysql-on-sqlite/tests/tools/ |
| 117 | + cp packages/mysql-on-sqlite/tests/mysql/data/*.csv \ |
| 118 | + ../baseline/packages/mysql-on-sqlite/tests/mysql/data/ 2>/dev/null || true |
| 119 | +
|
| 120 | + - name: Benchmark — baseline native path (walk, no identity cache) |
| 121 | + working-directory: ../baseline/packages/mysql-on-sqlite |
| 122 | + run: | |
| 123 | + BASE_EXT="$(realpath ../../packages/php-ext-wp-mysql-parser/target/release/libwp_mysql_parser.so)" |
| 124 | + php -d extension="$BASE_EXT" tests/tools/run-native-ast-walk-benchmark.php \ |
| 125 | + | tee "$GITHUB_WORKSPACE/packages/mysql-on-sqlite/baseline-native-walk.txt" |
| 126 | +
|
| 127 | + - name: Benchmark — baseline native path (parse only) |
| 128 | + working-directory: ../baseline/packages/mysql-on-sqlite |
| 129 | + run: | |
| 130 | + BASE_EXT="$(realpath ../../packages/php-ext-wp-mysql-parser/target/release/libwp_mysql_parser.so)" |
| 131 | + php -d extension="$BASE_EXT" tests/tools/run-native-ast-walk-benchmark.php --no-walk \ |
| 132 | + | tee "$GITHUB_WORKSPACE/packages/mysql-on-sqlite/baseline-native-parse-only.txt" |
| 133 | +
|
| 134 | + # Hit-heavy scenarios — these are where the per-AST identity cache is |
| 135 | + # supposed to win. The baseline reallocates wrappers on every accessor |
| 136 | + # call, while the PR reuses them. Run on both to make the gap visible. |
| 137 | + - name: Benchmark — native rewalk x10 (this PR) |
| 138 | + working-directory: packages/mysql-on-sqlite |
| 139 | + run: | |
| 140 | + php -d extension="$NATIVE_EXT" tests/tools/run-native-ast-walk-benchmark.php --mode=rewalk --repeat=10 \ |
| 141 | + | tee native-rewalk.txt |
| 142 | +
|
| 143 | + - name: Benchmark — baseline rewalk x10 |
| 144 | + working-directory: ../baseline/packages/mysql-on-sqlite |
| 145 | + run: | |
| 146 | + BASE_EXT="$(realpath ../../packages/php-ext-wp-mysql-parser/target/release/libwp_mysql_parser.so)" |
| 147 | + php -d extension="$BASE_EXT" tests/tools/run-native-ast-walk-benchmark.php --mode=rewalk --repeat=10 \ |
| 148 | + | tee "$GITHUB_WORKSPACE/packages/mysql-on-sqlite/baseline-native-rewalk.txt" |
| 149 | +
|
| 150 | + - name: Benchmark — native reread x20 (this PR) |
| 151 | + working-directory: packages/mysql-on-sqlite |
| 152 | + run: | |
| 153 | + php -d extension="$NATIVE_EXT" tests/tools/run-native-ast-walk-benchmark.php --mode=reread --repeat=20 \ |
| 154 | + | tee native-reread.txt |
| 155 | +
|
| 156 | + - name: Benchmark — baseline reread x20 |
| 157 | + working-directory: ../baseline/packages/mysql-on-sqlite |
| 158 | + run: | |
| 159 | + BASE_EXT="$(realpath ../../packages/php-ext-wp-mysql-parser/target/release/libwp_mysql_parser.so)" |
| 160 | + php -d extension="$BASE_EXT" tests/tools/run-native-ast-walk-benchmark.php --mode=reread --repeat=20 \ |
| 161 | + | tee "$GITHUB_WORKSPACE/packages/mysql-on-sqlite/baseline-native-reread.txt" |
| 162 | +
|
| 163 | + - name: Benchmark — native subtree x5 (this PR) |
| 164 | + working-directory: packages/mysql-on-sqlite |
| 165 | + run: | |
| 166 | + php -d extension="$NATIVE_EXT" tests/tools/run-native-ast-walk-benchmark.php --mode=subtree --repeat=5 \ |
| 167 | + | tee native-subtree.txt |
| 168 | +
|
| 169 | + - name: Benchmark — baseline subtree x5 |
| 170 | + working-directory: ../baseline/packages/mysql-on-sqlite |
| 171 | + run: | |
| 172 | + BASE_EXT="$(realpath ../../packages/php-ext-wp-mysql-parser/target/release/libwp_mysql_parser.so)" |
| 173 | + php -d extension="$BASE_EXT" tests/tools/run-native-ast-walk-benchmark.php --mode=subtree --repeat=5 \ |
| 174 | + | tee "$GITHUB_WORKSPACE/packages/mysql-on-sqlite/baseline-native-subtree.txt" |
| 175 | +
|
| 176 | + - name: Summarize |
| 177 | + if: always() |
| 178 | + working-directory: packages/mysql-on-sqlite |
| 179 | + run: | |
| 180 | + extract() { |
| 181 | + # Pull a numeric field (e.g. duration=1.23s) from a benchmark |
| 182 | + # output line. Returns "n/a" if missing. |
| 183 | + local file="$1" key="$2" |
| 184 | + [ -f "$file" ] || { echo "n/a"; return; } |
| 185 | + grep -oE "${key}=[^ ]+" "$file" | head -1 | cut -d= -f2 || echo "n/a" |
| 186 | + } |
| 187 | +
|
| 188 | + { |
| 189 | + echo '### Native AST walk perf' |
| 190 | + echo |
| 191 | + echo '| scenario | result |' |
| 192 | + echo '|---|---|' |
| 193 | + for f in php-parse-only.txt php-walk.txt native-parse-only.txt native-walk.txt baseline-native-parse-only.txt baseline-native-walk.txt native-rewalk.txt baseline-native-rewalk.txt native-reread.txt baseline-native-reread.txt native-subtree.txt baseline-native-subtree.txt; do |
| 194 | + [ -f "$f" ] || continue |
| 195 | + line="$(cat "$f")" |
| 196 | + echo "| ${f%.txt} | \`$line\` |" |
| 197 | + done |
| 198 | + echo |
| 199 | + echo '### Identity-cache cost (native walk: with cache vs PR base without)' |
| 200 | + echo |
| 201 | + echo '| metric | with cache (this PR) | baseline | delta |' |
| 202 | + echo '|---|---|---|---|' |
| 203 | + for key in duration qps peak_mem walked_nodes; do |
| 204 | + with="$(extract native-walk.txt "$key")" |
| 205 | + base="$(extract baseline-native-walk.txt "$key")" |
| 206 | + echo "| $key | $with | $base | — |" |
| 207 | + done |
| 208 | + } >> "$GITHUB_STEP_SUMMARY" |
| 209 | +
|
| 210 | + - name: Upload raw output |
| 211 | + if: always() |
| 212 | + uses: actions/upload-artifact@v4 |
| 213 | + with: |
| 214 | + name: native-ast-perf-${{ github.run_id }} |
| 215 | + path: packages/mysql-on-sqlite/*.txt |
| 216 | + if-no-files-found: warn |
0 commit comments