Skip to content

Commit 20891de

Browse files
committed
Run the lexer benchmark workflow on the MySQL parser package
The workflow now measures only the lexer in packages/mysql-parser, and it runs only when that lexer or its benchmark changes. The number of passes stays the same. The benchmark needs the Composer autoloader, so the workflow generates it first.
1 parent 8c39f65 commit 20891de

1 file changed

Lines changed: 27 additions & 12 deletions

File tree

‎.github/workflows/lexer-benchmark.yml‎

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ name: Lexer benchmark
33
on:
44
pull_request:
55
paths:
6-
- 'packages/mysql-on-sqlite/src/mysql/class-wp-mysql-lexer.php'
7-
- 'packages/mysql-on-sqlite/src/mysql/class-wp-mysql-token.php'
8-
- 'packages/mysql-on-sqlite/src/parser/class-wp-parser-token.php'
9-
- 'packages/mysql-on-sqlite/tests/tools/run-lexer-benchmark.php'
6+
- 'packages/mysql-parser/src/class-wp-mysql-lexer.php'
7+
- 'packages/mysql-parser/src/class-wp-mysql-token.php'
8+
- 'packages/mysql-parser/src/parser/class-wp-parser-token.php'
9+
- 'packages/mysql-parser/tests/benchmark.php'
1010
- '.github/workflows/lexer-benchmark.yml'
1111

1212
# A new push supersedes the previous run; the result comment is updated in place.
@@ -38,16 +38,29 @@ jobs:
3838
php-version: '8.4'
3939
coverage: none
4040

41+
- name: Generate the autoloader
42+
working-directory: packages/mysql-parser
43+
run: composer dump-autoload --no-interaction
44+
4145
- name: Benchmark base vs PR
4246
env:
4347
BASE_SHA: ${{ github.event.pull_request.base.sha }}
4448
run: |
45-
BENCH=packages/mysql-on-sqlite/tests/tools/run-lexer-benchmark.php
49+
BENCH=packages/mysql-parser/tests/benchmark.php
4650
47-
# Best-pass QPS for a given PHP flag set.
51+
# Best-pass QPS for a given PHP flag set. A lexer that throws looks fast, and a
52+
# crashed run prints no result, so both fail the job instead of posting a number.
4853
best() {
49-
php -d memory_limit=512M "$@" "$BENCH" --json \
50-
| php -r '$j = json_decode( stream_get_contents( STDIN ), true ); echo (int) $j["qps_best"];'
54+
php -d memory_limit=512M "$@" "$BENCH" --lexer-only --iterations=10 --warmup=3 --json \
55+
| php -r '
56+
$output = stream_get_contents( STDIN );
57+
$result = json_decode( $output, true );
58+
if ( ! $result || $result["exceptions"] > 0 ) {
59+
fwrite( STDERR, "The lexer benchmark failed:\n$output\n" );
60+
exit( 1 );
61+
}
62+
echo (int) $result["qps_best"];
63+
'
5164
}
5265
jit_flags="-d opcache.enable_cli=1 -d opcache.jit_buffer_size=64M -d opcache.jit=tracing"
5366
@@ -57,11 +70,13 @@ jobs:
5770
5871
# Swap only the source tree to the base commit and re-measure with the
5972
# same (PR) benchmark tool, so both sides are timed identically. The
60-
# benchmark tool itself (tests/tools/) is left at the PR version.
61-
git checkout "$BASE_SHA" -- packages/mysql-on-sqlite/src
73+
# benchmark tool itself (tests/) is left at the PR version. PR-only files
74+
# are removed and the classmap is rebuilt, so the base run can't load PR code.
75+
git checkout --no-overlay "$BASE_SHA" -- packages/mysql-parser/src
76+
composer dump-autoload --no-interaction --working-dir=packages/mysql-parser
6277
base_nojit=$( best )
6378
base_jit=$( best $jit_flags )
64-
git checkout HEAD -- packages/mysql-on-sqlite/src
79+
git checkout HEAD -- packages/mysql-parser/src
6580
6681
fmt() { php -r 'echo number_format( (int) $argv[1] );' "$1"; }
6782
ratio() { php -r 'printf( "%.2f", $argv[1] / max( 1, (int) $argv[2] ) );' "$1" "$2"; }
@@ -80,7 +95,7 @@ jobs:
8095
echo
8196
echo "To reproduce locally:"
8297
echo '```'
83-
echo "cd packages/mysql-on-sqlite && composer run bench-lexer"
98+
echo "cd packages/mysql-parser && composer dump-autoload && composer run benchmark -- --lexer-only"
8499
echo '```'
85100
} > "$RUNNER_TEMP/comment.md"
86101
echo "COMMENT_FILE=$RUNNER_TEMP/comment.md" >> "$GITHUB_ENV"

0 commit comments

Comments
 (0)