Skip to content

Commit 0173970

Browse files
carlos-granadosderickr
authored andcommitted
Add comments, add end of file newlines, fix php 8.5 compilation
1 parent 8d14ff0 commit 0173970

File tree

5 files changed

+58
-13
lines changed

5 files changed

+58
-13
lines changed

.github/benchmark-files/bench.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
<?php
2+
3+
/**
4+
* This file has been copied from the php-src project. It is just a php process that runs some fairly standard
5+
* algorithms and which serves as an artificial benchmark. We removed a couple of functions which were taking
6+
* long to run and which made these benchmarks too slow
7+
*/
8+
29
if (function_exists("date_default_timezone_set")) {
310
date_default_timezone_set("UTC");
411
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
; Needed so that the php scripts won't time out while being run
12
max_execution_time=0
3+
; We remove all error handling, printing and displaying so that it does not interfere with the tests
24
error_reporting=0
35
display_errors=off
46
log_errors=off
7+
; We enable the opcache both for cli and cgi modes, disable the jit compiler and disable opcache optimization
8+
; (so that the case where Xdebug is not loaded matches the case where it is loaded as Xdebug disables this optimization)
9+
; We also set opcache to use a file cache so that it can be shared between the two runs that we do of the Symfony code
510
opcache.enable=1
611
opcache.enable_cli=1
712
opcache.jit=disable
813
opcache.validate_timestamps=0
914
opcache.optimization_level=0
1015
opcache.file_cache=/tmp/opcache/
11-
opcache.file_cache_only=1
16+
opcache.file_cache_only=1

.github/benchmark-files/rector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
->withPaths([
1313
__DIR__ . '/.github/benchmark-files/rector.php',
1414
])
15-
;
15+
;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
zend_extension=xdebug.so
22
xdebug.start_with_request=no
3-
xdebug.max_nesting_level=2048
3+
; We need this because some of the functions in bench.php do deep recursion and the default nesting level is not enough
4+
xdebug.max_nesting_level=2048

.github/workflows/benchmark.yml

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
name: Benchmark Xdebug performance
22

33
on:
4+
# This workflow runs on three triggers: Weekly on schedule, manually or when pull requests are labeled
45
schedule:
56
# Every Sunday at 03:00 UTC
67
- cron: '0 3 * * 0'
78
workflow_dispatch:
89
pull_request:
9-
types: [opened, edited, reopened, synchronize]
10+
types: [ labeled ]
1011

1112
jobs:
1213
run-benchmark:
14+
# When triggered when a pull request is labeled we check the name of the label
1315
if: |
1416
github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' ||
1517
(
1618
github.event_name == 'pull_request' &&
17-
(
18-
startsWith(github.event.pull_request.title, 'perf:') ||
19-
startsWith(github.event.pull_request.title, 'Perf:') ||
20-
startsWith(github.event.pull_request.title, 'Performance:') ||
21-
startsWith(github.event.pull_request.title, 'performance:')
22-
)
19+
github.event.label.name == 'performance-check'
2320
)
2421
runs-on: ubuntu-latest
2522
strategy:
@@ -36,11 +33,13 @@ jobs:
3633
with:
3734
php-version: "${{ matrix.php }}"
3835
coverage: none
36+
# We need to use a specific version of Composer because we are using a specific version of the Symfony Demo
37+
# which is not compatible with the latest versions of Composer
3938
tools: composer:v2.2.21
4039

41-
# ASLR can cause a lot of noise due to missed sse opportunities for memcpy
42-
# and other operations, so we disable it during benchmarking.
4340
- name: Disable ASLR
41+
# ASLR can cause a lot of noise due to missed sse opportunities for memcpy
42+
# and other operations, so we disable it during benchmarking.
4443
run: echo 0 | sudo tee /proc/sys/kernel/randomize_va_space
4544

4645
- name: Install valgrind
@@ -58,6 +57,10 @@ jobs:
5857
5958
- name: install Symfony demo
6059
if: matrix.command == 'symfony'
60+
# For versions of PHP greater than 8.4 we need to run a different version of the Symfony Demo.
61+
# The older versions suffer from the nulllable parameter deprecation and this generated a lot of deprecations
62+
# in the code and this skewed the tests results a lot. And we cannot use the newer version for older versions
63+
# of PHP as it is not compatible.
6164
run: |
6265
if [ "${{ matrix.php }}" \< "8.4" ]; then
6366
version="v2.0.2"
@@ -67,6 +70,10 @@ jobs:
6770
git clone -q --branch "$version" --depth 1 https://github.com/symfony/demo.git ./symfony-demo
6871
cd symfony-demo
6972
composer install
73+
# We do not want our tests to be skewed by any error, warning, notice or deprecation thrown by the code,
74+
# so we set the error level to 0 on purpose. Unfortunately, Symfony overrides this setup and sets their own
75+
# error reporting level. We fix this by changing all the places where Symfony is setting the error reporting
76+
# level so that it continues to be set to 0
7077
find . -type f -name "*.php" -exec sed -i.bak -E 's/error_reporting\(.*\);/error_reporting(0);/g' {} +
7178
7279
- name: install Rector
@@ -97,19 +104,30 @@ jobs:
97104
if: matrix.command == 'symfony'
98105
run: |
99106
cd symfony-demo
107+
# The Symfony demo is run using php-cgi to simulate a web server. Symfony needs that this env variable is set,
108+
# it would usually be set by the web server, we need to set it manually instead
100109
export SCRIPT_FILENAME="$(realpath public/index.php)"
110+
# Symfony also needs this to be set to a non empty value
111+
export APP_SECRET=APP_SECRET
112+
# We run the web page twice so that the files have already been compiled into the opcache in order to remove
113+
# the compilation time from the equation. This also better reflects the normal situation in a web server
101114
php-cgi public/index.php
102115
valgrind --tool=callgrind --dump-instr=yes --callgrind-out-file=callgrind.out -- php-cgi public/index.php
103116
mv callgrind.out ..
104117
cd ..
105118
106119
- name: benchmark rector.php
107-
if: matrix.command == 'rector'
120+
if: matrix.command == 'rector'
121+
# Rector needs to be run with the --xdebug flag so that it does not try to disable Xdebug
122+
# and also with the --debug flag so that it does not try to run several threads in parallel
108123
run: valgrind --tool=callgrind --dump-instr=yes --callgrind-out-file=callgrind.out -- php vendor/bin/rector --dry-run --xdebug --debug || true
109124

110125
- name: save matrix values
111126
run: |
127+
# We read the number of executed instructions from the callgrind.out file and save it in an artifact
128+
# to be processed later
112129
awk '/^summary:/ { print $2 }' callgrind.out > results/php-${{ matrix.php }}_cmd-${{ matrix.command }}_xdebug-${{ matrix.xdebug_mode }}.txt
130+
# We also save the matrix variables so that in a later step we can build a list of the executed options
113131
echo "${{ matrix.php }},${{ matrix.command }},${{ matrix.xdebug_mode }}" > results/matrix-values-${{ matrix.php }}-${{ matrix.command }}-${{ matrix.xdebug_mode }}.txt
114132
115133
- name: Upload result and matrix info
@@ -119,6 +137,8 @@ jobs:
119137
path: results/
120138

121139
performance:
140+
# After running all benchmarks for all commands, php versions and Xdebug modes we run a new job that builds
141+
# a summary of all execution times
122142
needs: run-benchmark
123143
runs-on: ubuntu-latest
124144
steps:
@@ -128,6 +148,8 @@ jobs:
128148
path: results
129149

130150
- name: Merge matrix values
151+
# We copy all the saved result files into a single folder and build a file with a list
152+
# of all matrix variables used
131153
run: |
132154
mkdir merged
133155
find results -name '*.txt' -exec cp {} merged/ \;
@@ -136,13 +158,16 @@ jobs:
136158
137159
- name: Generate summary table
138160
run: |
161+
# This is needed to be able to print the number of instructions using commas for separators
139162
export LC_NUMERIC=en_US.UTF-8
140163
echo "# 🕒 Performance Results" > summary.md
141164
165+
# We build lists of the different matrix options used in the previous jobs
142166
commands=$(cut -d',' -f2 unique-matrix-values.txt | sort | uniq)
143167
php_versions=$(cut -d',' -f1 unique-matrix-values.txt | sort | uniq)
144168
xdebug_modes=$(cut -d',' -f3 unique-matrix-values.txt | sort | uniq)
145169
170+
# And we loop over all these versions building a summary with tables of all the values
146171
for command in $commands; do
147172
echo "" >> summary.md
148173
echo "## **Command:** \`$command\`" >> summary.md
@@ -153,6 +178,8 @@ jobs:
153178
echo "| Xdebug | Instructions | Slowdown |" >> summary.md
154179
echo "|--------|-------------:|---------:|" >> summary.md
155180
181+
# To calculate the slowdown, we read a base value which is taken from the data
182+
# where Xdebug mode is "no" (it was not loaded)
156183
base_file="merged/php-${php}_cmd-${command}_xdebug-no.txt"
157184
base_value=$(cat "$base_file")
158185
for xdebug in $xdebug_modes; do
@@ -164,6 +191,7 @@ jobs:
164191
else
165192
slowdown=$(awk -v v=$value -v b=$base_value 'BEGIN { printf "%.1f%%", ((v - b) * 100) / b }')
166193
fi
194+
# The number of instructions is formatted with thousands separators
167195
formatted_value=$(printf "%'d" "$value")
168196
echo "| $xdebug | $formatted_value | $slowdown |" >> summary.md
169197
fi
@@ -172,9 +200,13 @@ jobs:
172200
done
173201
174202
- name: print summary
203+
# This generated summary file is copied into a special file which GitHub has defined
204+
# in this special env variable and it will use it to print a summary for the workflow
175205
run: cat summary.md >> $GITHUB_STEP_SUMMARY
176206

177207
- name: delete intermediary artifacts
208+
# The intermediate files that we generated are not needed and can be deleted,
209+
# helping us keep the summary page clean
178210
uses: geekyeggo/delete-artifact@v5
179211
with:
180212
name: results-*

0 commit comments

Comments
 (0)