typetools / checker-framework

Pluggable type-checking for Java
http://checkerframework.org/
Other
1.03k stars 355 forks source link

gradlew reformat takes 25 seconds even for back-to-back executions #3735

Open vlsi opened 4 years ago

vlsi commented 4 years ago

Build scan: https://scans.gradle.com/s/v3h4b4q56gj42/timeline

It would be nice if ./gradlew reformat was incremental.

mernst commented 4 years ago

I agree it takes too long. The problem is that it calls run-google-java-format, which itself makes multiple passes over every file. The best way for you to improve this would be to upvote or comment on https://github.com/google/google-java-format/issues/5. run-google-java-format has a hard-coded list of known type annotations, and it ought to be straightforward for google-java-format to take this approach as well.

To avoid re-checking, run-google-java-format could cache the hash of each file that is correctly annotated, and avoid any work for such a file. That would address your concern. Feel free to open a pull request.

(I don't encounter this problem because I don't run ./gradlew reformat. My editor automatically runs run-google-java-format every time I save a file.)

vlsi commented 4 years ago

A slightly different angle might be to use https://github.com/autostyle/autostyle or https://github.com/diffplug/spotless to drive the formatter. Then incremental processing will be done by Gradle.

Thanks for the pointers though.

mernst commented 4 years ago

Can autostyle and spotless call out to an external formatter? If their default formatting is wrong for type annotations (as that of google-java-format is), they would need to invoke run-google-java-format. If they can do so, that would be a worthwhile integration to write. If they cannot do so, then run-google-java-format (currently written in Python) could be re-implemented as a plugin to one of them.

(Is autostyle a hard fork of spotless? The README doesn't state the relationship between them.)

vlsi commented 4 years ago

Can autostyle and spotless call out to an external formatter?

Most of the formatters are external. I guess run-google-java-format could be plugged.

Is autostyle a hard fork of spotless?

It is. Here's background: https://github.com/autostyle/autostyle/issues/20#issuecomment-646220048