Skip to content

ADFA-6854: Check Kotlin library scope membership by root instead of per-entry sets - #2228

Draft
itsaky-adfa wants to merge 1 commit into
stagefrom
perf/ADFA-6854-library-scope
Draft

itsaky-adfa wants to merge 1 commit into
stagefrom
perf/ADFA-6854-library-scope

Conversation

@itsaky-adfa

Copy link
Copy Markdown
Contributor

Draft, part 1 of 4 of the ADFA-6854 stack. The stack keeps one compact listing per library JAR shared by the Java and Kotlin LSPs, instead of four copies. Do not merge yet: see "Open items" in the top PR.

Stack (bottom to top):

  1. This PR: Kotlin library scopes check membership by root
  2. javac package map shared per JAR
  3. JarListing: one packed index per JAR for zipfs2 and javac
  4. Lazy Kotlin VFS over JarListing (needs a kt-android release)

What

KtLibraryModule no longer keeps, per library module, a Set of every entry URL (baseContentScope) or a files scope over every entry VirtualFile (computeBaseContentScope(), inherited from AbstractKtModule). Both now go through LibraryRootsScope. That scope holds only the module's root files and answers contains(vf) with an ancestor-or-self walk to a root.

Why

After opening CoGo's own codebase (405 library JARs, ~137k entries), the URL sets alone held 41.4 MB, ~315 B per entry, because every URL repeats the JAR path. The files scope also pinned a VirtualFile for every entry of every library, which keeps the Kotlin VFS from ever being lazy. PR 4 relies on that.

Behaviour

  • The scope contains the same files as before, for JAR roots, class directories and jrt module roots. KtLibraryModuleScopeTest checks this file by file against the old URL set.
  • A class directory that gains files after the scope is built now contains them; the old snapshot did not.
  • No CoGo code walks library JAR trees any more. FindUsages, ScanningWorker and DirectInheritorsProvider walk source modules only.

Measured

OnePlus Pad 2, cold open of CoGo at stage ffaa75be84, heap dump 60 s after both index markers. The numbers cover the whole stack.

stage stack
KtLibraryModule scope data 41.4 MB 0.3 MB

Tests

  • KtLibraryModuleScopeTest: 4 tests. "Added later" and "holds only its roots" fail on stage.
  • :lsp:kotlin:testV7DebugUnitTest: 633/633.

@atlassian

atlassian Bot commented Nov 6, 2026

Copy link
Copy Markdown

To enable Code Reviewer, link your GitHub account to your Atlassian account.

This is a one-time task that takes less than a minute. Once your account is linked, resubmit the pull request to trigger a code review.

@itsaky-adfa
itsaky-adfa added this pull request to stack #2232 November 6, 2026 15:21
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.

1 participant