-
Notifications
You must be signed in to change notification settings - Fork 73
Use Worker API for process isolation in Spotless
#1492
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
base: develop
Are you sure you want to change the base?
Conversation
Generate changelog in
|
...tir-java-format/src/main/groovy/com/palantir/javaformat/gradle/PalantirJavaFormatPlugin.java
Outdated
Show resolved
Hide resolved
|
|
||
| private String formatWithWorker(String input, Iterable<File> jars) throws IOException { | ||
| // Create temp files for input/output communication with worker | ||
| File inputFile = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the best way I could come-up with to get the formatted string in and out
| parameters.getFormatterClasspath().from(jars); | ||
| }); | ||
|
|
||
| workQueue.await(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to await to ensure formatting is done
Spotless
✅ Successfully generated changelog entry!Need to regenerate?Simply interact with the changelog bot comment again to regenerate these entries. 📋Changelog Preview💡 Improvements
|
| try { | ||
| Files.writeString(inputFile.toPath(), input); | ||
|
|
||
| WorkQueue workQueue = workerExecutor.processIsolation(workerSpec -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm failure rate has increased to about 30% I wonder if this is just adding loads of overhead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we are creating a temp io file and a new worker for every single file
| private static final Logger logger = Logging.getLogger(FormatJavaWorkAction.class); | ||
|
|
||
| private static final Supplier<FormatterService> formatterService = Suppliers.memoize(() -> { | ||
| logger.info("Loading FormatterService in worker daemon"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running this locally, does it log this per file or just once per gradle invocation? Not sure is gradle is doing something funky with classloaders even in process isolation that means this may be new each time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
once per gradle invocation - or at least per spotless invocation:
> Task :foo-api:spotlessJava
Formatting file #1 in worker - classIdentity=269645944, file=palantir-java-format-input-1956597832421626908.java
Loading FormatterService in worker daemon - classLoader=VisitableURLClassLoader(worker-loader), classIdentity=269645944
> Task :foo:spotlessJava
Formatting file #1 in worker - classIdentity=687141933, file=palantir-java-format-input-12790676627999507747.java
Loading FormatterService in worker daemon - classLoader=VisitableURLClassLoader(worker-loader), classIdentity=687141933
Formatting file #2 in worker - classIdentity=269645944, file=palantir-java-format-input-1807148048456068675.java
Formatting file #2 in worker - classIdentity=687141933, file=palantir-java-format-input-12981619963290984761.java
Formatting file #3 in worker - classIdentity=269645944, file=palantir-java-format-input-13174205067034597682.java
Formatting file #3 in worker - classIdentity=687141933, file=palantir-java-format-input-7978830245738795631.java
Before this PR
palantir-java-formatran in-process forSpotlessintegrationAfter this PR
Spotlessuses Gradle's Worker API with process isolation==COMMIT_MSG==
Use Worker API for process isolation in Spotless and FormatDiff
Migrates
Spotlessintegration to use Gradle's WorkerAPI with process isolation. Provides better error messages and prevents
formatter crashes from affecting the main build daemon.
==COMMIT_MSG==
Possible downsides?