Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/backward-compatibility-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ name: "Backward Compatibility Check"
on:
pull_request:

concurrency:
group: ${{ github.workflow_ref }}
cancel-in-progress: true

jobs:
roave-backwards-compatibility-check:
name: "Backward Compatibility Check"
Expand All @@ -27,7 +31,7 @@ jobs:
fetch-depth: 0

- name: "Install PHP"
uses: "shivammathur/setup-php@2.37.2"
uses: "shivammathur/setup-php@2.40.0"
with:
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1
Expand Down
68 changes: 37 additions & 31 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ name: "Benchmark"
on:
pull_request:

concurrency:
group: ${{ github.workflow_ref }}
cancel-in-progress: true

jobs:
phpbench:
name: "Benchmark"
Expand All @@ -22,11 +26,11 @@ jobs:

steps:
- name: "Install PHP"
uses: "shivammathur/setup-php@2.37.2"
uses: "shivammathur/setup-php@2.40.0"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1, opcache.enable_cli=1, opcache.jit=tracing, opcache.jit_buffer_size=64M
ini-values: memory_limit=-1

- name: "Checkout base"
uses: actions/checkout@v7
Expand All @@ -38,7 +42,7 @@ jobs:
dependency-versions: ${{ matrix.dependencies }}

- name: "phpbench on base"
run: "vendor/bin/phpbench run tests/Benchmark --progress=none --report=default --tag=base"
run: "vendor/bin/phpbench run tests/Benchmark --progress=none --tag=base"

- name: "Checkout"
uses: actions/checkout@v7
Expand All @@ -50,46 +54,44 @@ jobs:
dependency-versions: ${{ matrix.dependencies }}

- name: "phpbench diff"
id: bench
continue-on-error: true
run: "vendor/bin/phpbench run tests/Benchmark --progress=none --report=diff --ref=base > bench.txt"

- name: "Get Bench Result"
id: phpbench
run: |
echo 'BENCH_RESULT<<EOF' >> $GITHUB_ENV
cat bench.txt >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV

- uses: actions/github-script@v9
with:
script: |
const fs = require('fs');

// the diff report prints one section per benchmark class: a title line, a console table, a blank line.
// The console table becomes a markdown table by dropping the outer borders and turning the border
// below the header into the separator row.
const sections = fs.readFileSync('bench.txt', 'utf8').trim().split(/\n\s*\n/).map((section) => {
const [title, , header, separator, ...rows] = section.trim().split('\n');
const table = [header, separator.replace(/\+/g, '|'), ...rows.filter((row) => !row.startsWith('+'))];

return `### ${title.replace(/Bench$/, '')}\n\n${table.join('\n')}`;
}).join('\n\n');

const failed = ${{ steps.bench.outcome == 'failure' }};
const commentBody = `Hello :wave:

Here are the most recent benchmark results, compared against \`${{ github.base_ref }}\`. Time is the mode over the iterations in the \`its\` column, with the relative standard deviation in brackets.

${sections}

${failed ? ':warning: At least one benchmark got slower than the tolerance in phpbench.json allows.' : ''}
This comment gets updated every time a new commit comes in.`;

// Get the existing comments.
const {data: comments} = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.number,
})

// Find any comment already made by the bot.
const botComment = comments.find(comment => comment.user.id === 41898282)
const commentBody = `

Hello :wave:

<details>
<summary>here is the most recent benchmark result:</summary>

<p>

\`\`\`
${{ env.BENCH_RESULT }}
\`\`\`

</p>
</details>

This comment gets update everytime a new commit comes in!

`;
// Find any comment already made by the bot.
const botComment = comments.find(comment => comment.user.id === 41898282)

if (!context.payload.pull_request.head.repo.full_name.startsWith('patchlevel/')) {
console.log('Not attempting to write comment on PR from fork');
Expand All @@ -110,3 +112,7 @@ jobs:
})
}
}

- name: "Fail on regression"
if: steps.bench.outcome == 'failure'
run: "exit 1"
6 changes: 5 additions & 1 deletion .github/workflows/coding-standard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:
- "[0-9]+.[0-9]+.x"
- "renovate/*"

concurrency:
group: ${{ github.workflow_ref }}
cancel-in-progress: true

jobs:
static-analysis-coding-standard:
name: "Static Analysis by patchlevel/coding-standard"
Expand All @@ -29,7 +33,7 @@ jobs:
uses: actions/checkout@v7

- name: "Install PHP"
uses: "shivammathur/setup-php@2.37.2"
uses: "shivammathur/setup-php@2.40.0"
with:
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/docs-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ on:
branches:
- "[0-9]+.[0-9]+.x"

concurrency:
group: ${{ github.workflow_ref }}
cancel-in-progress: true

jobs:
checkdocs:
name: "Check Docs"
Expand All @@ -28,7 +32,7 @@ jobs:
uses: actions/checkout@v7

- name: "Install PHP"
uses: "shivammathur/setup-php@2.37.2"
uses: "shivammathur/setup-php@2.40.0"
with:
coverage: none
php-version: "${{ matrix.php-version }}"
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/mutation-tests-diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ name: "Mutation tests on diff"
on:
pull_request:

concurrency:
group: ${{ github.workflow_ref }}
cancel-in-progress: true

jobs:
mutation-tests-diff:
name: "Mutation tests on diff"
Expand All @@ -27,7 +31,7 @@ jobs:
fetch-depth: 0

- name: "Install PHP"
uses: "shivammathur/setup-php@2.37.2"
uses: "shivammathur/setup-php@2.40.0"
with:
coverage: "pcov"
php-version: "${{ matrix.php-version }}"
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/mutation-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:
- "[0-9]+.[0-9]+.x"
- "renovate/*"

concurrency:
group: ${{ github.workflow_ref }}
cancel-in-progress: true

jobs:
mutation-tests:
name: "Mutation tests"
Expand All @@ -29,7 +33,7 @@ jobs:
uses: actions/checkout@v7

- name: "Install PHP"
uses: "shivammathur/setup-php@2.37.2"
uses: "shivammathur/setup-php@2.40.0"
with:
coverage: "pcov"
php-version: "${{ matrix.php-version }}"
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:
- "[0-9]+.[0-9]+.x"
- "renovate/*"

concurrency:
group: ${{ github.workflow_ref }}
cancel-in-progress: true

jobs:
static-analysis-phpstan:
name: "Static Analysis by PHPStan"
Expand All @@ -29,7 +33,7 @@ jobs:
uses: actions/checkout@v7

- name: "Install PHP"
uses: "shivammathur/setup-php@2.37.2"
uses: "shivammathur/setup-php@2.40.0"
with:
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:
- "[0-9]+.[0-9]+.x"
- "renovate/*"

concurrency:
group: ${{ github.workflow_ref }}
cancel-in-progress: true

jobs:
phpunit:
name: "Unit tests"
Expand Down Expand Up @@ -46,7 +50,7 @@ jobs:
uses: actions/checkout@v7

- name: "Install PHP"
uses: "shivammathur/setup-php@2.37.2"
uses: "shivammathur/setup-php@2.40.0"
with:
coverage: "pcov"
php-version: "${{ matrix.php-version }}"
Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ snapshot: vendor
UPDATE_SNAPSHOTS=1 vendor/bin/phpunit --no-coverage --filter testGeneratedCodeMatchesSnapshot

.PHONY: benchmark
benchmark: vendor ## run benchmarks
vendor/bin/phpbench run tests/Benchmark --report=default
benchmark: vendor ## run all benchmarks
vendor/bin/phpbench run --report=diff

.PHONY: benchmark-diff-test
benchmark-diff-test: vendor ## run benchmarks
vendor/bin/phpbench run tests/Benchmark --revs=1 --report=default --progress=none --tag=base
vendor/bin/phpbench run tests/Benchmark --revs=1 --report=diff --progress=none --ref=base
.PHONY: benchmark-diff
benchmark-diff: vendor ## run the benchmarks twice and compare the second run against the first, like the CI does
vendor/bin/phpbench run --progress=none --tag=base
vendor/bin/phpbench run --progress=none --report=diff --ref=base


.PHONY: docs
Expand Down
77 changes: 30 additions & 47 deletions phpbench.json
Original file line number Diff line number Diff line change
@@ -1,54 +1,37 @@
{
"$schema":"./vendor/phpbench/phpbench/phpbench.schema.json",
"$schema": "./vendor/phpbench/phpbench/phpbench.schema.json",
"runner.bootstrap": "vendor/autoload.php",
"runner.path": "tests/Benchmark",
"runner.file_pattern": "*Bench.php",
"runner.iterations": 5,
"runner.php_config": {
"memory_limit": "-1",
"opcache.enable_cli": 1,
"opcache.jit_buffer_size": 0,
"xdebug.mode": "off"
},
"runner.assert": "mode(variant.time.avg) <= mode(baseline.time.avg) +/- 25%",
"report.generators": {
"diff": {
"generator": "component",
"partition": ["benchmark_name"],
"components": [
{
"component": "section",
"title": "{{ first(frame[\"benchmark_name\"]) }}",
"components": [
{
"component": "table_aggregate",
"partition": ["subject_name", "variant_name"],
"groups":
{
"time (kde mode)":
{
"cols": ["time"]
},
"memory":
{
"cols": ["memory"]
}
},
"row":
{
"subject": "first(partition[\"subject_name\"]) ~ \" (\" ~ first(partition[\"variant_name\"]) ~ \")\"",
"time":
{
"type": "expand",
"partition": "suite_tag",
"cols":
{
"Tag: {{ key }}": "mode(partition[\"result_time_avg\"]) as time ~ ' (' ~ rstdev(partition['result_time_avg']) ~ ')'"
}
},
"memory":
{
"type": "expand",
"partition": "suite_tag",
"cols":
{
"Tag: {{ key }} ": "mode(partition[\"result_mem_peak\"]) as memory"
}
}
}
}]
}]
"generator": "expression",
"break": [
"benchmark"
],
"cols": [
"subject",
"revs",
"its",
"memory",
"base",
"current",
"diff"
],
"expressions": {
"memory": "if(first(has_baseline), (first(result_mem_peak) as memory) ~ ' ' ~ percent_diff(first(baseline_mem_peak), first(result_mem_peak)), first(result_mem_peak) as memory)",
"base": "if(first(has_baseline), mode(baseline_time_avg) as time ~ ' (' ~ rstdev(baseline_time_avg) ~ ')', '')",
"current": "mode(result_time_avg) as time ~ ' (' ~ rstdev(result_time_avg) ~ ')'",
"diff": "if(first(has_baseline), percent_diff(mode(baseline_time_avg), mode(result_time_avg), rstdev(result_time_avg)), '')"
}
}
}
}
}
22 changes: 22 additions & 0 deletions src/Metadata/CacheKey.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Patchlevel\Hydrator\Metadata;

use function hash;

/**
* PSR-6 and PSR-16 reserve the characters {}()/\@: and only guarantee keys up to 64 characters,
* so class names are hashed instead of being used as they are.
*
* @internal
*/
final class CacheKey
{
/** @param class-string $class */
public static function forClass(string $class): string
{
return 'hydrator_metadata_' . hash('xxh128', $class);
}
}
6 changes: 5 additions & 1 deletion src/Metadata/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ public function __serialize(): array
/** @param serialized $data */
public function __unserialize(array $data): void
{
$this->reflection = new ReflectionClass($data['className']);
/** @var class-string<T> $className */
$className = $data['className'];

$this->reflection = new ReflectionClass($className);
$this->className = $className;
$this->normalizer = $data['normalizer'];
$this->properties = $data['properties'];
$this->lazy = $data['lazy'];
Expand Down
Loading
Loading