Skip to content

Conversation

@nevil06
Copy link

@nevil06 nevil06 commented Dec 11, 2025

… fix KSP performance regression

  • Added declaredFieldsCache and declaredMethodsCache to avoid repeated expensive KSP API calls
  • Implemented getCachedDeclaredFields() and getCachedDeclaredMethods() helper methods
  • Updated validateForMembersInjectionInternalUncached() to use cached results
  • Updated clearCache() to invalidate new caches

This optimization addresses the 3x performance regression when using KSP compared to KAPT. Flame chart analysis showed getDeclaredFields() and getDeclaredMethods() were dominating execution time due to repeated calls for the same types. Caching these results should reduce KSP API calls by 50-70% and significantly improve build times.

… fix KSP performance regression

- Added declaredFieldsCache and declaredMethodsCache to avoid repeated expensive KSP API calls
- Implemented getCachedDeclaredFields() and getCachedDeclaredMethods() helper methods
- Updated validateForMembersInjectionInternalUncached() to use cached results
- Updated clearCache() to invalidate new caches

This optimization addresses the 3x performance regression when using KSP compared to KAPT.
Flame chart analysis showed getDeclaredFields() and getDeclaredMethods() were dominating
execution time due to repeated calls for the same types. Caching these results should
reduce KSP API calls by 50-70% and significantly improve build times.
@google-cla
Copy link

google-cla bot commented Dec 11, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@bcorso
Copy link

bcorso commented Dec 11, 2025

Thanks for looking into Dagger performance!

Can you also try using the HEAD-SNAPSHOT artifacts and post the results? We've been working on KSP performance the last few months but the recent improvements aren't in the latest release. Or if you're building from source can you sync the repo (I updated the XProcessing jars 2 days ago in fb2eed2).

I'm a bit surprised that the caches should be necessary since the type elements should already be cached by the XTypeElementStore and the declared methods and fields should already be cached by KspTypeElement (e.g. see _declaredFields and _declaredMethods are by lazy).

If it still looks like performance is an issue we can submit this as a stop-gap and I'll investigate why the existing XProcessing caches aren't taking affect because ideally these caches should be added in XProcessing rather than Dagger.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants