Conversation
In `dropCaches()`, KSP previously called `publishGlobalModuleStateModificationEvent()`, `KaSessionProvider.getInstance(project).clearCaches()`, `psiManager.dropResolveCaches()`, `psiManager.dropPsiCaches()`, and `KSObjectCacheManager.clear()` on each round. KSP rounds only add newly generated source files to `KaSourceModule` and do not mutate binary libraries or dependencies (`KaLibraryModule`). Calling `publishGlobalModuleStateModificationEvent()` forces Analysis API and FIR to discard all binary/library symbol provider and Java class caches, which then have to be recomputed from scratch in every subsequent round. Switching to `publishGlobalSourceModuleStateModificationEvent()` preserves library caches across rounds while properly invalidating source module caches. Additionally: - `KaSessionProvider.getInstance(project).clearCaches()` is redundant because `KaSessionProvider` already subscribes to `KotlinModificationEvent` and clears caches when modification events are published. - `psiManager.dropResolveCaches()` is redundant because `psiManager.dropPsiCaches()` already calls `dropResolveCaches()`.
Author
|
There's some more context including benchmark results in internal bug b/567808367, I am seeing a ~9% wall time improvement for one large KSP action from this. |
jaschdoc
reviewed
Oct 5, 2026
jaschdoc
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for the PR. Reducing the number of manual calls is a good idea. Before I approve, I just want to ask @hfmehmed, do you see any problems with not clearing library caches in KMP setups? If we have commonMain and a terminal compilation task, how does KSP run now? Is processing run on commonMain first and its sources and generated sources available to the terminal compilation task as a library?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In
dropCaches(), KSP previously calledpublishGlobalModuleStateModificationEvent(),KaSessionProvider.getInstance(project).clearCaches(),psiManager.dropResolveCaches(),psiManager.dropPsiCaches(), andKSObjectCacheManager.clear()on each round.KSP rounds only add newly generated source files to
KaSourceModuleand donot mutate binary libraries or dependencies (
KaLibraryModule). CallingpublishGlobalModuleStateModificationEvent()forces Analysis API and FIRto discard all binary/library symbol provider and Java class caches, which then
have to be recomputed from scratch in every subsequent round.
Switching to
publishGlobalSourceModuleStateModificationEvent()preserveslibrary caches across rounds while properly invalidating source module caches.
Additionally:
KaSessionProvider.getInstance(project).clearCaches()is redundant becauseKaSessionProvideralready subscribes toKotlinModificationEventandclears caches when modification events are published.
psiManager.dropResolveCaches()is redundant becausepsiManager.dropPsiCaches()already callsdropResolveCaches().