Skip to content

KSP2: reuse processor classloaders across modules within a build - #3210

Merged
hfmehmed merged 1 commit into
google:mainfrom
hfmehmed:perf/cache-processor-classloader
Sep 17, 2026
Merged

hfmehmed merged 1 commit into
google:mainfrom
hfmehmed:perf/cache-processor-classloader

Conversation

@hfmehmed

@hfmehmed hfmehmed commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

KspAAWorkerAction constructs a fresh URLClassLoader over the processor
classpath for every module and closes it when that module finishes. The same
processor jars are therefore loaded and compiled once per module.

This PR adds an opt-in cache of processor classloaders keyed by the KSP classpath
plus the processor classpath. It lives alongside the existing isolated classloader
cache and is cleared by the same build service, so its lifetime is still bounded
by the build.

Results

Measured on the Metro 500-module Dagger/KSP benchmark, ABI-change scenario,
via gradle-profiler with 3 warm-ups and 6 measured iterations. The same ksp binary is used - one of them has a flag set to enable the cache and the other represents the baseline (current state)

Median Mean Range
Cache OFF 85.58s 86.75s 84.52 – 91.52s
Cache ON 57.74s 57.69s 55.30 – 59.97s
Delta −27.84s (−32.5%) −29.07s (−33.5%) —

Overlap between the two states: NO - 24.55s difference between the slowest cache-ON build (59.97s) and the fastest cache-OFF build (84.52s).

Screenshot 2026-09-15 at 18 05 26

@jaschdoc
jaschdoc self-requested a review September 15, 2026 14:49
@hfmehmed
hfmehmed force-pushed the perf/cache-processor-classloader branch from eb3478d to 191ec00 Compare September 15, 2026 15:48

@jaschdoc jaschdoc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly nits and questions. Looks like a nice optimization!

@jaschdoc jaschdoc added the performance KSP performance, e.g., reducing build times for users label Sep 16, 2026
@hfmehmed
hfmehmed force-pushed the perf/cache-processor-classloader branch from 191ec00 to f1a75ea Compare September 16, 2026 14:19

@jaschdoc jaschdoc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good!

@hfmehmed
hfmehmed added this pull request to the merge queue Sep 17, 2026
Merged via the queue into google:main with commit 102d2ff Sep 17, 2026
28 checks passed
@hfmehmed
hfmehmed deleted the perf/cache-processor-classloader branch September 17, 2026 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance KSP performance, e.g., reducing build times for users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants