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

Pre-commit formatting hook is slow #6297

Closed
msridhar opened this issue Nov 12, 2023 · 1 comment · Fixed by #6383
Closed

Pre-commit formatting hook is slow #6297

msridhar opened this issue Nov 12, 2023 · 1 comment · Fixed by #6383
Assignees

Comments

@msridhar
Copy link
Contributor

I noticed that even on my M1 Mac the pre-commit hook to check formatting takes more than 10 seconds. I ran a Gradle build scan and looked at the performance:

https://scans.gradle.com/s/uiupezpubbyf2/performance/execution

It looks like a great deal of time is spent in top-level :spotlessGroovyGradle, :spotlessJava, and :spotlessMisc tasks. I wonder if these tasks are doing formatting checks redundant with similarly-named tasks defined for the sub-projects? If we could scope these top-level tasks to only include files not covered by a sub-project task that could speed things up.

As a workaround, since I mostly just edit Java source code, I run ./gradlew spotlessJavaApply to fix formatting (which skips format checking of Gradle and misc files), and then git commit --no-verify to skip the pre-commit hook.

@msridhar
Copy link
Contributor Author

Also note that in the build scan, all the tasks are up to date; it takes 10 seconds just to do fingerprinting and confirm that the tasks do not need to be run. This is part of what makes me suspect that at least the inputs for the top-level tasks are too broad.

smillst pushed a commit that referenced this issue Jan 3, 2024
Fixes #6297 

We make two key changes:

1. Split formatting of `.java` source files among individual sub-projects, so formatting / checking for each sub-project can run in parallel.
2. Remove exclusion patterns that start in `**`, which are expensive to evaluate.

With these changes, `./gradlew spotlessCheck` (which runs in the pre-commit script) runs much faster for me (on my M1 Mac the running time is reduced from ~9.2 seconds before this PR to ~2 seconds after).

To test, we add tasks named `printSpotlessTaskInputs` that print which files are being formatted.  Using these tasks I confirmed that exactly the same files are being checked and formatted before and after this PR.
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 a pull request may close this issue.

2 participants