Commit 3ac2bc4
authored
Optimize codenarc task on rerun (#11677)
refactor: Apply normalization on every project
perf: Insulate the BuildTimeInstrumentationPlugin from changes using a ClasspathNormalizer
BuildTimeInstrumentationPlugin install a post-processing step onto
normal compile tasks.
Flow:
1. It creates a resolvable `buildTimeInstrumentationPlugin`
configuration
2. For each main `compileJava` / `compileGroovy` / `compileScala` task,
it registers that configuration as a **compile-task input**
3. Then appends a `doLast("instrumentClasses", ...)` action to
post-process compiled classes. That action runs Byte Buddy plugins
against the compiled class output.
If any input for that task changes, the whole compile task reruns.
In particular the Byte Buddy plugins are tracked via
```kotlin
inputs.files(project.configurations.named(BUILD_TIME_INSTRUMENTATION_PLUGIN_CONFIGURATION))
```
In particular instrumentation plugins rely on instrumentation plugins
coming from `agent-tooling` project which also happens to have a version
file
```Gradle
subProj.configurations.named('buildTimeInstrumentationPlugin') {
it.dependencies.add(subProj.dependencies.project(
path: ':dd-java-agent:agent-tooling',
configuration: 'buildTimeInstrumentationToolingPlugins'
))
```
Before the normalizer, Gradle hashed the full jar contents of the
build-time instrumentation plugin classpath. And as such the jars on
that configuration changed only because their generated *.version
changed after a new Git commit. And as such invalidated the task output.
Adding the normalizer to this input only teaches Gradle to use the
normalizaton declared in the project to ignore the version file on
this input.
Important nuance: `ClasspathNormalizer` is better than
`CompileClasspathNormalizer` here. These are Byte Buddy plugins executed
at build time, so method-body/resource changes in those plugin jars
can change generated bytecode. We only want to ignore the known
volatile version resource.
---
Before this change the compile task amounted to a significant part when
only the commit version changed
```
327.901s compile*
10.486s codenarcTest
9.576s *Jar
8.217s process*Resources
2.208s expandAgentShadowJar*
2.032s generate*Index
1.241s writeVersionNumberFile
```
After this change
```
14.780s compile* # up-to-date checking, not recompilation
7.469s process*Resources
6.194s *Jar
5.056s codenarcTest
2.233s writeVersionNumberFile
1.847s generate*Index
0.899s expandAgentShadowJar*
```
Co-authored-by: brice.dutheil <brice.dutheil@datadoghq.com>1 parent 477a0ce commit 3ac2bc4
4 files changed
Lines changed: 10 additions & 68 deletions
File tree
- buildSrc/src
- main/kotlin/datadog/gradle/plugin
- instrument
- version
- test/kotlin/datadog/gradle/plugin/version
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
69 | 76 | | |
70 | 77 | | |
71 | 78 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
115 | 116 | | |
116 | 117 | | |
117 | 118 | | |
| 119 | + | |
| 120 | + | |
118 | 121 | | |
119 | 122 | | |
120 | 123 | | |
| |||
Lines changed: 0 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | 13 | | |
15 | 14 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | 15 | | |
25 | 16 | | |
26 | 17 | | |
| |||
Lines changed: 0 additions & 59 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | 128 | | |
188 | 129 | | |
189 | 130 | | |
| |||
0 commit comments