Skip to content
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

Tests: improve performance of the sniff tests #351

Merged
merged 1 commit into from
Feb 24, 2024

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Feb 20, 2024

Description

The Fixer::generateDiff() method uses shell_exec() with the diff command to generate a file diff.

Using this command is slow, in particular on Windows.

This commit introduces a preliminary check in the test logic to see if a diff is even needed and skips generating the diff if no differences are expected.

I don't know whether and if so, how much this will make a difference for *nix users, but on Windows, it makes a significant difference when running the sniff tests.

A run of just the sniff tests (vendor/bin/phpunit tests/AllTests.php --filter Standards --no-coverage) for PHPCS without this fix takes > 1 minute (~01.03.701 last time I ran it).
With this fix, the run time of the sniff tests is brought down to ~8 seconds.

So let's call this a quality of life improvement for all devs which regularly need to run sniff tests for either PHPCS itself or for external standards which base their test suite on the PHPCS native test framework.

👉🏻 Request for testing:

Based on the test runs in CI, this change should make no significant different on *nix systems, but I'd love to have some people test it and post their with and without timing results.

Suggested changelog entry

Performance improvements for the sniff tests. Should be most notable for Windows users.

@rodrigoprimo
Copy link
Contributor

Based on the test runs in CI, this change should make no significant different on *nix systems, but I'd love to have some people test it and post their with and without timing results.

I tested this on my Ubuntu machine using the command vendor/bin/phpunit tests/AllTests.php --filter Standards --no-coverage, and I saw a small improvement. I did only a few runs on the main branch and on this branch. On the main branch, it takes around 5.4 seconds for the command to finish. On this branch, it takes around 4.7 seconds.

The `Fixer::generateDiff()` method uses `shell_exec()` with the `diff` command to generate a file diff.

Using this command is slow, in particular on Windows.

This commit introduces a preliminary check in the test logic to see if a diff is even needed and skips generating the diff if no differences are expected.

I don't know whether and if so, how much this will make a difference for *nix users, but on Windows, it makes a significant difference when running the sniff tests.

A run of just the sniff tests without this fix takes > 1 minute (~01.03.701 last time I ran it).
With this fix, the run time of the sniff tests is brought down to ~8 seconds.

So let's call this a quality of life improvement for all devs which regularly need to run sniff tests for either PHPCS itself or for external standards which base their test suite on the PHPCS native test framework.
@jrfnl jrfnl force-pushed the feature/tests-improve-performance-fixer-diff-check branch from b06aa0f to f3eac53 Compare February 24, 2024 09:52
@jrfnl
Copy link
Member Author

jrfnl commented Feb 24, 2024

Rebased without changes. Merging once the build passes.

@jrfnl jrfnl merged commit 53f374c into master Feb 24, 2024
44 checks passed
@jrfnl jrfnl deleted the feature/tests-improve-performance-fixer-diff-check branch February 24, 2024 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants