Skip to content

Conversation

@samsonasik
Copy link
Member

@samsonasik samsonasik commented Sep 20, 2025

@staabm this is the rework effort from the old PR:

I tested with diff on json format, it keep same, see https://www.diffchecker.com/YtVb6oKF/

The process is:

  • Use DefaultDiffer->diff() as default value
  • When pass to FileDiff::__construct() on diffConsoleFormatted, it call
$this->colorConsoleDiffFormatter->format($diff)

like this:

        $diff = $shouldShowDiffs ? $this->defaultDiffer->diff($oldContent, $newContent) : '';
        $consoleDiff = $shouldShowDiffs ? $this->colorConsoleDiffFormatter->format($diff) : '';

        // always keep the most recent diff
        return new FileDiff(
            $relativeFilePath,
            $diff,
            $consoleDiff,
            $rectorsWithLineChanges
        );

Then, to keep the string @@ @@, I use regex on ColorConsoleDiffFormatter->diff().

@samsonasik samsonasik changed the title [Differ] Remove DefaultDiffer, use ConsoleDiffer instead to avoid double diffing process [Differ] Remove ConsoleDiffer, use DefaultDiffer that utilize ColorConsoleDiffFormatter instead to avoid double diffing process Sep 20, 2025
…nsoleDiffFormatter instead to avoid double diffing process

fix cs
@samsonasik
Copy link
Member Author

All checks have passed 🎉 @TomasVotruba it is ready for review.

@staabm
Copy link
Contributor

staabm commented Sep 21, 2025

my intial motivation for this change was performance.

did you check whether this new implementation is faster then the previous one?

@samsonasik
Copy link
Member Author

Not yet check on a large diff. The check may need a large diff on a single run to see comparison, yes?

@staabm
Copy link
Contributor

staabm commented Sep 21, 2025

IIRC the reproducer is described in rectorphp/rector#7899

@samsonasik
Copy link
Member Author

I tried that, seems 1 second faster:

Before

bin/rector --clear-cache --dry-run  8.33s user 0.09s system 99% cpu 8.441 total

After

bin/rector --clear-cache --dry-run  6.86s user 0.10s system 98% cpu 7.064 total

@samsonasik
Copy link
Member Author

Updated stop loop on found --- Original and +++ New, got new result:

Before

bin/rector --clear-cache --dry-run  8.33s user 0.09s system 99% cpu 8.441 total

After

bin/rector --clear-cache --dry-run  6.93s user 0.09s system 99% cpu 7.033 total

@TomasVotruba
Copy link
Member

@samsonasik What are numbers on one if our private client's project? Real projects are better than Rector itself

@samsonasik
Copy link
Member Author

samsonasik commented Sep 21, 2025

@TomasVotruba yes, the measure is depends on how many files changed, more diffs, more faster.

I tried in our project with 70 files changed, that means there are diffs, it 3 seconds faster.

Before

../rector-src/bin/rector process src --dry-run --clear-cache  796.63s user 21.67s system 652% cpu 2:05.41 total

After

../rector-src/bin/rector process src --dry-run --clear-cache  772.05s user 20.86s system 647% cpu 2:02.38 total

@samsonasik
Copy link
Member Author

samsonasik commented Sep 21, 2025

@TomasVotruba I've updated with reduce loop, remove array_map, and it seems faster 7 seconds now, applied 70 files changes, tested on our project:

Before 2:05.41

../rector-src/bin/rector process src --dry-run --clear-cache  796.63s user 21.67s system 652% cpu 2:05.41 total

After 1:58.40

../rector-src/bin/rector process src --dry-run --clear-cache  752.03s user 19.20s system 651% cpu 1:58.40 total

@TomasVotruba TomasVotruba merged commit 20db305 into main Sep 29, 2025
50 checks passed
@TomasVotruba TomasVotruba deleted the differ branch September 29, 2025 11:22
@TomasVotruba
Copy link
Member

Let's give it a try 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants