You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Format a single file on the calling thread, without a thread pool #227
Main.formatFiles creates a fixed pool of min(20, files) threads whatever the number of files, so a single file is read on the main thread, formatted on a pool thread and taken back with Future.get. Standard input already formats on the calling thread: formatStdin calls FormatFileCallable.call() directly.
One file on the command line is the common case: the pre-commit hook and the GitHub Action run the native binary once for each file, as --dry-run --set-exit-if-changed "$FILE", and code that runs Main in process creates and closes a pool on every call.
What the pool costs
Little. The 21.0.2 native binary on java/util/ArrayList.java of JDK 21, median of 30 runs: 111.0 ms with the file as an argument, 110.6 ms with it on standard input. The gain is one code path less and no thread to start and stop, not time.
Proposal
With one Java file left after the others are skipped, format it on the calling thread, as formatStdin does, and report its errors as the pooled path does: the diagnostics of a FormatterException, the message and stack trace of any other exception.
google-java-format
The same: formatFiles creates min(MAX_THREADS, files) threads for one file too.
Activity