Skip to content

Commit

Permalink
Improve performance in SynthesizeDependenciesTask.
Browse files Browse the repository at this point in the history
  • Loading branch information
autonomousapps committed Nov 19, 2022
1 parent 97dfabd commit 3ea6f79
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/main/kotlin/com/autonomousapps/internal/OutputPaths.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ internal class OutputPaths(
private val graphDir = "${variantDirectory}/graph"
val compileGraphPath = file("${graphDir}/graph-compile.json")
val compileGraphDotPath = file("${graphDir}/graph-compile.gv")
val compileNodesPath = file("${graphDir}/graph-compile-nodes.json")
val runtimeGraphPath = file("${graphDir}/graph-runtime.json")
val runtimeGraphDotPath = file("${graphDir}/graph-runtime.gv")
val dominatorConsolePath = file("${graphDir}/graph-dominator.txt")
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/com/autonomousapps/model/Coordinates.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,5 @@ data class IncludedBuildCoordinates(
)
}
}

internal class CoordinatesContainer(val coordinates: Set<Coordinates>)
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ internal class ProjectPlugin(private val project: Project) {

output.set(outputPaths.compileGraphPath)
outputDot.set(outputPaths.compileGraphDotPath)
outputNodes.set(outputPaths.compileNodesPath)
outputRuntime.set(outputPaths.runtimeGraphPath)
outputRuntimeDot.set(outputPaths.runtimeGraphDotPath)
}
Expand Down Expand Up @@ -630,7 +631,7 @@ internal class ProjectPlugin(private val project: Project) {
tasks.register<SynthesizeDependenciesTask>("synthesizeDependencies$taskNameSuffix") {
inMemoryCache.set(inMemoryCacheProvider)
projectPath.set(thisProjectPath)
graphView.set(graphViewTask.flatMap { it.output })
compileDependencies.set(graphViewTask.flatMap { it.outputNodes })
physicalArtifacts.set(artifactsReportTask.flatMap { it.output })
explodedJars.set(explodeJarTask.flatMap { it.output })
inlineMembers.set(inlineTask.flatMap { it.output })
Expand Down
7 changes: 7 additions & 0 deletions src/main/kotlin/com/autonomousapps/tasks/GraphViewTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.autonomousapps.internal.graph.GraphViewBuilder
import com.autonomousapps.internal.graph.GraphWriter
import com.autonomousapps.internal.utils.getAndDelete
import com.autonomousapps.internal.utils.toJson
import com.autonomousapps.model.CoordinatesContainer
import com.autonomousapps.model.DependencyGraphView
import com.autonomousapps.model.declaration.SourceSetKind
import com.autonomousapps.model.declaration.Variant
Expand Down Expand Up @@ -81,6 +82,10 @@ abstract class GraphViewTask : DefaultTask() {
@get:OutputFile
abstract val output: RegularFileProperty

/** Output in json format for compile classpath dependencies (the graph's nodes). */
@get:OutputFile
abstract val outputNodes: RegularFileProperty

/** Output in graphviz format for compile classpath graph. */
@get:OutputFile
abstract val outputDot: RegularFileProperty
Expand All @@ -96,6 +101,7 @@ abstract class GraphViewTask : DefaultTask() {
@TaskAction fun action() {
val output = output.getAndDelete()
val outputDot = outputDot.getAndDelete()
val outputNodes = outputNodes.getAndDelete()
val outputRuntime = outputRuntime.getAndDelete()
val outputRuntimeDot = outputRuntimeDot.getAndDelete()

Expand All @@ -115,6 +121,7 @@ abstract class GraphViewTask : DefaultTask() {

output.writeText(compileGraphView.toJson())
outputDot.writeText(GraphWriter.toDot(compileGraph))
outputNodes.writeText(CoordinatesContainer(compileGraphView.nodes).toJson())
outputRuntime.writeText(runtimeGraphView.toJson())
outputRuntimeDot.writeText(GraphWriter.toDot(runtimeGraph))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ abstract class SynthesizeDependenciesTask @Inject constructor(

@get:PathSensitive(PathSensitivity.NONE)
@get:InputFile
abstract val graphView: RegularFileProperty
abstract val compileDependencies: RegularFileProperty

@get:PathSensitive(PathSensitivity.NONE)
@get:InputFile
Expand Down Expand Up @@ -90,7 +90,7 @@ abstract class SynthesizeDependenciesTask @Inject constructor(
@TaskAction fun action() {
workerExecutor.noIsolation().submit(SynthesizeDependenciesWorkAction::class.java) {
inMemoryCache.set(this@SynthesizeDependenciesTask.inMemoryCache)
graphView.set(this@SynthesizeDependenciesTask.graphView)
compileDependencies.set(this@SynthesizeDependenciesTask.compileDependencies)
physicalArtifacts.set(this@SynthesizeDependenciesTask.physicalArtifacts)
explodedJars.set(this@SynthesizeDependenciesTask.explodedJars)
inlineMembers.set(this@SynthesizeDependenciesTask.inlineMembers)
Expand All @@ -106,7 +106,7 @@ abstract class SynthesizeDependenciesTask @Inject constructor(

interface SynthesizeDependenciesParameters : WorkParameters {
val inMemoryCache: Property<InMemoryCache>
val graphView: RegularFileProperty
val compileDependencies: RegularFileProperty
val physicalArtifacts: RegularFileProperty
val explodedJars: RegularFileProperty
val inlineMembers: RegularFileProperty
Expand All @@ -129,7 +129,7 @@ abstract class SynthesizeDependenciesTask @Inject constructor(
override fun execute() {
val outputDir = parameters.outputDir

val graphView = parameters.graphView.fromJson<DependencyGraphView>()
val dependencies = parameters.compileDependencies.fromJson<CoordinatesContainer>().coordinates
val physicalArtifacts = parameters.physicalArtifacts.fromJsonSet<PhysicalArtifact>()
val explodedJars = parameters.explodedJars.fromJsonSet<ExplodedJar>()
val inlineMembers = parameters.inlineMembers.fromJsonSet<InlineMemberDependency>()
Expand All @@ -151,15 +151,15 @@ abstract class SynthesizeDependenciesTask @Inject constructor(

// A dependency can appear in the graph even though it's just a .pom (.module) file. E.g., kotlinx-coroutines-core.
// This is a fallback so all such dependencies have a file written to disk.
graphView.nodes.forEach { node ->
dependencies.forEach { node ->
// Do not add dependencies that are already known again
val coordinatesAlreadyKnow = builders.values.any {
val coordinatesAlreadyKnown = builders.values.any {
it.coordinates == node ||
// If the node is pointing at a project, there might already be an artifact
// stored under matching IncludedBuildCoordinates.
it.coordinates is IncludedBuildCoordinates && it.coordinates.resolvedProject == node
// If the node is pointing at a project, there might already be an artifact
// stored under matching IncludedBuildCoordinates.
it.coordinates is IncludedBuildCoordinates && it.coordinates.resolvedProject == node
}
if (!coordinatesAlreadyKnow) {
if (!coordinatesAlreadyKnown) {
builders.merge(
node,
DependencyBuilder(node),
Expand Down

0 comments on commit 3ea6f79

Please sign in to comment.