Skip to content

Commit 1ae3bc3

Browse files
committed
Two performance fixes without which the build takes minutes in the configuration phase for multi-module projects with a lot of cross-references.
1. Loads the plugin just one time, instead of loading separately for each module. Debug logging showed that sometimes, this operations takes 10 sec (on some machines at least). 2. The more critical issue was in `recursiveDependenciesOf`. Without caching of the results, the same operations are repeated over and over again and it takes minutes to configure. For a work project I have, with 16 modules, with a lot of cross-references, adding the scoverage plugin without these fixes takes 5-10 mins. The worst of it is that this is the wait time for each change in any build.gradle (e.g. adding a new dependency), which makes the work nearly impossible. After applying the fixes, there is no significant difference with the time taken without the scoverage plugin.
1 parent 5366cef commit 1ae3bc3

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/main/groovy/org/scoverage/ScoveragePlugin.groovy

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.gradle.api.tasks.SourceSet
1010
import org.gradle.api.tasks.scala.ScalaCompile
1111

1212
import java.nio.file.Files
13+
import java.util.concurrent.ConcurrentHashMap
1314

1415
import static groovy.io.FileType.FILES
1516

@@ -23,6 +24,9 @@ class ScoveragePlugin implements Plugin<PluginAware> {
2324

2425
static final String DEFAULT_REPORT_DIR = 'reports' + File.separatorChar + 'scoverage'
2526

27+
private volatile File pluginFile = null
28+
private ConcurrentHashMap<Task, Set<? extends Task>> taskDependencies = new ConcurrentHashMap<>();
29+
2630
@Override
2731
void apply(PluginAware pluginAware) {
2832
if (pluginAware instanceof Project) {
@@ -174,9 +178,12 @@ class ScoveragePlugin implements Plugin<PluginAware> {
174178
}
175179

176180
compileTask.configure {
177-
File pluginFile = project.configurations[CONFIGURATION_NAME].find {
178-
it.name.startsWith("scalac-scoverage-plugin")
181+
if (pluginFile == null) {
182+
pluginFile = project.configurations[CONFIGURATION_NAME].find {
183+
it.name.startsWith("scalac-scoverage-plugin")
184+
}
179185
}
186+
180187
List<String> parameters = ['-Xplugin:' + pluginFile.absolutePath]
181188
List<String> existingParameters = scalaCompileOptions.additionalParameters
182189
if (existingParameters) {
@@ -269,9 +276,15 @@ class ScoveragePlugin implements Plugin<PluginAware> {
269276
}
270277

271278
private Set<? extends Task> recursiveDependenciesOf(Task task) {
279+
if (!taskDependencies.containsKey(task)) {
280+
def directDependencies = task.getTaskDependencies().getDependencies(task)
281+
def nestedDependencies = directDependencies.collect {recursiveDependenciesOf(it) }.flatten()
282+
def dependencies = directDependencies + nestedDependencies
272283

273-
def directDependencies = task.getTaskDependencies().getDependencies(task)
274-
def nestedDependencies = directDependencies.collect {recursiveDependenciesOf(it) }.flatten()
275-
return directDependencies + nestedDependencies
284+
taskDependencies.put(task, dependencies)
285+
return dependencies
286+
} else {
287+
return taskDependencies.get(task)
288+
}
276289
}
277290
}

0 commit comments

Comments
 (0)