AST transformations are executed during the compilation process and can significantly impact build performance. The Groovy documentation explicitly
recommends using @CompileStatic for AST transformation implementations because it improves compiler performance.
When AST transformations are not compiled statically, they rely on Groovy’s dynamic features during compilation, which adds overhead. Since AST
transformations can be invoked many times during a single compilation (potentially once per source file for global transformations, or once per
annotation occurrence for local transformations), this performance overhead can accumulate and noticeably slow down build times.
Using @CompileStatic eliminates this dynamic overhead by ensuring the transformation code itself is optimized at compile time, leading
to faster execution when the transformation is applied.
What is the potential impact?
Without @CompileStatic, AST transformations will execute more slowly during compilation, leading to increased build times. This
performance impact becomes more significant in larger codebases or when transformations are applied frequently. The overhead can accumulate across
multiple transformation invocations, making builds noticeably slower.