-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Improve perf and add conveniences #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2f8786b
feat: Improve perf and add conveniences
tymondesigns f1589c5
tweaks
tymondesigns 400ca26
add param
tymondesigns a4d6ab8
spli tests
tymondesigns 96b359d
run bench in CI
tymondesigns 0dccd5e
add to pr
tymondesigns 99da22b
improve
tymondesigns ce884f8
fixes
tymondesigns ab8376e
fixes
tymondesigns 36a85a7
increase tolerance
tymondesigns 4158464
more fixes
tymondesigns 8421300
more fixes
tymondesigns File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| name: Benchmarks | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| on: | ||
| pull_request: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| benchmark: | ||
| runs-on: ubuntu-latest | ||
| name: Benchmark regression | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Setup PHP and Composer | ||
| uses: ./.github/actions/setup-php-composer | ||
| with: | ||
| php-version: 8.3 | ||
|
|
||
| # Store a baseline from the PR's base branch on this same runner, so the | ||
| # comparison is hardware-consistent (baselines are never committed). | ||
| - name: Store baseline from base branch | ||
| run: | | ||
| git checkout ${{ github.event.pull_request.base.sha }} | ||
| composer install --prefer-dist --no-interaction --no-progress | ||
| vendor/bin/phpbench run --tag=base --progress=none | ||
|
|
||
| - name: Compare PR against baseline | ||
| id: compare | ||
| run: | | ||
| git checkout ${{ github.event.pull_request.head.sha }} | ||
| composer install --prefer-dist --no-interaction --no-progress | ||
| set +e | ||
| vendor/bin/phpbench run \ | ||
| --ref=base \ | ||
| --report=aggregate \ | ||
| --progress=none \ | ||
| --no-ansi \ | ||
| --assert="mode(variant.time.avg) <= mode(baseline.time.avg) +/- 25%" \ | ||
| > benchmark-report.txt 2>&1 | ||
| echo "exit_code=$?" >> "$GITHUB_OUTPUT" | ||
| cat benchmark-report.txt | ||
|
|
||
| - name: Write job summary | ||
| if: always() | ||
| run: | | ||
| { | ||
| echo "## Benchmark results" | ||
| echo | ||
| echo '```' | ||
| cat benchmark-report.txt | ||
| echo '```' | ||
| } >> "$GITHUB_STEP_SUMMARY" | ||
|
|
||
| - name: Comment results on PR | ||
| if: always() | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const fs = require('fs'); | ||
| const report = fs.readFileSync('benchmark-report.txt', 'utf8'); | ||
| const passed = '${{ steps.compare.outputs.exit_code }}' === '0'; | ||
| const status = passed | ||
| ? 'No performance regression detected (within 25% tolerance).' | ||
| : 'Possible performance regression detected (exceeds 25% tolerance).'; | ||
| const marker = '<!-- phpbench-regression -->'; | ||
| const body = [ | ||
| marker, | ||
| '## Benchmark results', | ||
| '', | ||
| status, | ||
| '', | ||
| '<details>', | ||
| '<summary>Aggregate report vs. base</summary>', | ||
| '', | ||
| '```', | ||
| report, | ||
| '```', | ||
| '', | ||
| '</details>', | ||
| '', | ||
| `_Compared against base \`${context.payload.pull_request.base.sha.slice(0, 7)}\`._`, | ||
| ].join('\n'); | ||
| const { owner, repo } = context.repo; | ||
| const issue_number = context.payload.pull_request.number; | ||
| const { data: comments } = await github.rest.issues.listComments({ owner, repo, issue_number }); | ||
| const existing = comments.find((c) => c.body && c.body.includes(marker)); | ||
| if (existing) { | ||
| await github.rest.issues.updateComment({ owner, repo, comment_id: existing.id, body }); | ||
| } else { | ||
| await github.rest.issues.createComment({ owner, repo, issue_number, body }); | ||
| } | ||
|
|
||
| - name: Fail on regression | ||
| if: always() && steps.compare.outputs.exit_code != '0' | ||
| run: | | ||
| echo "Benchmark regression exceeded the configured tolerance." | ||
| exit 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| vendor | ||
| composer.lock | ||
| .phpbench | ||
| .vscode | ||
| .env | ||
| .DS_Store | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Cortex\JsonRepair\Concerns; | ||
|
|
||
| /** | ||
| * @mixin \Cortex\JsonRepair\JsonRepairer | ||
| */ | ||
| trait OutputTracking | ||
| { | ||
| private ?string $lastNonWhitespaceChar = null; | ||
|
|
||
| private int $outputSyncedLength = 0; | ||
|
|
||
| private function resetOutputTracking(): void | ||
| { | ||
| $this->lastNonWhitespaceChar = null; | ||
| $this->outputSyncedLength = 0; | ||
| } | ||
|
|
||
| private function syncOutputTail(): void | ||
| { | ||
| $length = strlen($this->output); | ||
|
|
||
| if ($length === $this->outputSyncedLength) { | ||
| return; | ||
| } | ||
|
|
||
| $trimmed = rtrim(substr($this->output, $this->outputSyncedLength), " \t\n\r\f\v"); | ||
|
|
||
| if ($trimmed !== '') { | ||
| $this->lastNonWhitespaceChar = $trimmed[strlen($trimmed) - 1]; | ||
| } | ||
|
|
||
| $this->outputSyncedLength = $length; | ||
| } | ||
|
|
||
| private function recalculateLastNonWhitespaceChar(): void | ||
| { | ||
| $trimmed = rtrim($this->output); | ||
| $this->lastNonWhitespaceChar = $trimmed === '' ? null : $trimmed[strlen($trimmed) - 1]; | ||
| $this->outputSyncedLength = strlen($this->output); | ||
| } | ||
|
|
||
| private function outputEndsWithNonWhitespace(string $char): bool | ||
| { | ||
| $this->syncOutputTail(); | ||
|
|
||
| return $this->lastNonWhitespaceChar === $char; | ||
| } | ||
|
|
||
| private function trimOutputTrailingWhitespace(): void | ||
| { | ||
| if ($this->output === '') { | ||
| return; | ||
| } | ||
|
|
||
| $lastChar = $this->output[strlen($this->output) - 1]; | ||
|
|
||
| if (in_array($lastChar, [' ', "\t", "\n", "\r", "\f", "\v"], true)) { | ||
| $this->output = rtrim($this->output); | ||
| $this->recalculateLastNonWhitespaceChar(); | ||
| } | ||
| } | ||
|
|
||
| private function truncateOutput(int $length): void | ||
| { | ||
| $this->output = substr($this->output, 0, $length); | ||
| $this->recalculateLastNonWhitespaceChar(); | ||
| } | ||
|
|
||
| private function setOutput(string $output): void | ||
| { | ||
| $this->output = $output; | ||
| $this->recalculateLastNonWhitespaceChar(); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.