dweiss commented on code in PR #14824:
URL: https://github.com/apache/lucene/pull/14824#discussion_r2159970826


##########
build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/spotless/ParentGoogleJavaFormatTask.java:
##########
@@ -0,0 +1,69 @@
+package org.apache.lucene.gradle.plugins.spotless;
+
+import com.google.googlejavaformat.java.Formatter;
+import com.google.googlejavaformat.java.JavaFormatterOptions;
+import org.gradle.api.DefaultTask;
+import org.gradle.api.file.ConfigurableFileCollection;
+import org.gradle.api.file.FileType;
+import org.gradle.api.file.ProjectLayout;
+import org.gradle.api.file.RegularFileProperty;
+import org.gradle.api.tasks.InputFiles;
+import org.gradle.api.tasks.Internal;
+import org.gradle.api.tasks.OutputFile;
+import org.gradle.api.tasks.PathSensitive;
+import org.gradle.api.tasks.PathSensitivity;
+import org.gradle.work.ChangeType;
+import org.gradle.work.FileChange;
+import org.gradle.work.Incremental;
+import org.gradle.work.InputChanges;
+import org.gradle.workers.WorkQueue;
+import org.gradle.workers.WorkerExecutor;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.util.List;
+import java.util.stream.StreamSupport;
+
+abstract class ParentGoogleJavaFormatTask extends DefaultTask {
+    @Incremental
+    @InputFiles
+    @PathSensitive(PathSensitivity.RELATIVE)
+    public abstract ConfigurableFileCollection getSourceFiles();
+
+    @OutputFile
+    public abstract RegularFileProperty getOutputChangeListFile();
+
+    @Inject
+    protected abstract WorkerExecutor getWorkerExecutor();
+
+    public ParentGoogleJavaFormatTask(ProjectLayout layout, String gjfTask) {
+        
getOutputChangeListFile().convention(layout.getBuildDirectory().file("gjf-" + 
gjfTask + ".txt"));
+    }
+
+    protected static Formatter getFormatter() {
+        JavaFormatterOptions options =
+                JavaFormatterOptions.builder()
+                        .style(JavaFormatterOptions.Style.GOOGLE)
+                        .formatJavadoc(true)
+                        .reorderModifiers(true)
+                        .build();
+        return new Formatter(options);
+    }
+
+    protected List<File> getIncrementalBatch(InputChanges inputChanges) {
+        return 
StreamSupport.stream(inputChanges.getFileChanges(getSourceFiles()).spliterator(),
 false)
+                .filter(fileChange -> {
+                    return fileChange.getFileType() == FileType.FILE &&
+                           (fileChange.getChangeType() == ChangeType.ADDED ||
+                            fileChange.getChangeType() == ChangeType.MODIFIED);
+                })
+                .map(FileChange::getFile)
+                .toList();
+    }
+
+    @Internal
+    protected WorkQueue getWorkQueue() {
+        // TODO: maybe fork a separate jvm so that we can pass open-module 
settings there and fine-tune the jvm for the task?
+        return getWorkerExecutor().noIsolation();
+    }

Review Comment:
   I have already experimented with this (multiple files per worker). The 
problem is that they're not balanced - lucene/core has a lot more files than 
anything else, it's the long tail.
   
   I also used process isolation but this won't fly - I have 24 workers level 
on my machine and this results in dozens of forked jvms - it costs memory and 
overhead of booting up those additional JVMs. I'll experiment some more though. 
Thanks for your feedback.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to