-
-
Notifications
You must be signed in to change notification settings - Fork 392
Improve file-diffing performance #3705
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
Conversation
ff0f5e2
to
3bd89ce
Compare
I don't get why only e2e tests are failling @TomasVotruba @samsonasik any idea? |
it probably related with due to rector-src/e2e/e2eTestRunner.php Line 21 in 0451834
|
@staabm you can try e2e test locally by run:
|
the only missing thing is the "first-line-number" in the file diffs, see e.g. https://github.com/rectorphp/rector-src/actions/runs/4838521883/jobs/8623019152?pr=3705 before this PR we were able to always tell about this line number, because we calculated each file-diff in both modes - and file numbers are only available in the "default-differ". I guess if we want this perf improvement, we need to give up on this "first-line" number indication in the diff in parallel mode. wdyt? |
The line number in diff is a feature to ease jump to nearest changed code. That's strange, I will look if I can do something |
Oh, it seems you fix it? |
I think I found the glitch. lets see |
ohh lol. we now have the first line numbers, but also some more line numbers which we probably don't want? :) |
use Rector\Core\ValueObject\ProcessResult; | ||
use Rector\Parallel\ValueObject\Bridge; | ||
|
||
final class WorkerOutputFormatter implements OutputFormatterInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have introduced this new formatter, so I can easily differentiate between a user requesting json format and a user requesting a different format, but rector is internally using json format while delegating to worker processes.
that was necessary for this PR to implement the pre-existing behaviour
@TomasVotruba do you think adding more detailed diff line numbers in diffs is a good thing and I should change test-expectations? https://github.com/rectorphp/rector-src/actions/runs/4838587500/jobs/8623121975?pr=3705 |
More detailed diff is ok for me 👍 |
Hm..., not sure about DX perspective..., that probably cause ambiguous meaning when see the line change... |
@@ -17,7 +17,7 @@ public function __construct( | |||
) { | |||
// @see https://github.com/sebastianbergmann/diff#strictunifieddiffoutputbuilder | |||
// @see https://github.com/sebastianbergmann/diff/compare/4.0.4...5.0.0#diff-251edf56a6344c03fa264a4926b06c2cee43c25f66192d5f39ebee912b7442dc for upgrade | |||
$unifiedDiffOutputBuilder = new UnifiedDiffOutputBuilder(); | |||
$unifiedDiffOutputBuilder = new UnifiedDiffOutputBuilder( "--- Original\n+++ New\n", true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@staabm this may probably related of how original + new diff on Console formatter, see
rector-src/src/Console/Formatter/ColorConsoleDiffFormatter.php
Lines 66 to 71 in d7a738c
if ($escapedDiffLine === '--- Original') { | |
unset($escapedDiffLines[$key]); | |
} | |
if ($escapedDiffLine === '+++ New') { | |
unset($escapedDiffLines[$key]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this value is the same as the one this class used by default before this PR
7189e31
to
7f9b152
Compare
phpstan job requires #3716 to succeed |
on a different workload the PR improves considerably (in comparison to e3c1d08) even after all those PRs (this one included), diffing still dominates my profiles 🤷♂️. |
Worker command line test seems error, probably related of changed format from json to worker https://github.com/rectorphp/rector-src/actions/runs/4844443238/jobs/8632724411#step:5:40 |
b770e87
to
d9adf30
Compare
added more detailed line numbers
@@ -4,7 +4,7 @@ | |||
1) src/short_open_tag_with_import_name.php:0 | |||
|
|||
---------- begin diff ---------- | |||
@@ @@ | |||
@@ -1,10 +1,12 @@ | |||
<?php | |||
+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This somehow change the original expectation
+use PhpParser\Node\Stmt\Expression; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First stmt detection maybe changed, you may need to debug on
rector-src/packages/PostRector/Rector/NameImportingPostRector.php
Lines 58 to 61 in 5c1be93
$currentStmt = current($file->getNewStmts()); | |
if ($currentStmt instanceof FileWithoutNamespace && current($currentStmt->stmts) instanceof InlineHTML) { | |
return null; | |
} |
I need to take a few more measure, but I think I was able to fix the underlying problem in sebastianbergmann/diff, which might make this PR here obsolete |
@staabm thank you, I think patch to sebastianbergmann/diff is the right approach 👍 , we can just need to wait for next sebastianbergmann/diff release |
This PR is no longer necessary. I wrote a blog post about it https://staabm.github.io/2023/05/01/diff-speeding.html |
different approach on fixing rectorphp/rector#7899
after this PR we..