revelc/formatter-maven-plugin

Allow to use concurrent threads for faster formatting

Opened this issue · 3 comments

With a 8 core M1 then when we run a clean build of Apache Camel Core then it takes 5 seconds to check all the source code files

[INFO] --- formatter-maven-plugin:2.17.0:format (format) @ camel-core ---
[INFO] Processed 2625 files in 5s26ms (Formatted: 0, Unchanged: 2625, Failed: 0, Readonly: 0)

To my understanding this is done using a single thread.

Because each file is independent then we could allow to run this with a thread pool where we can use multiple threads. For example number of cores - 1 (leave 1 core for computer to be responsive).

This would be nice. My main concern is that some of the formatters might not be thread safe. It would make sense to initialize them once, and then reuse them for each applicable file. DEBUG log messages might get messy, too, if the formatters are running concurrently, but I don't think that's a big deal. At least, we can address that if necessary later.

Running a parallel stream of files would make this trivial to implement in the built-in shared ForkJoinPool, but the ResultCollector would have to switch to using AtomicLong for its counters.

@davsclaus Any change you had time to look into what this might take on this end? A possible PR might help.

@hazendaz sorry I have not tried this