Skip to content

use JDK 25 AOT Cache features to improve startup performance #1774

Closed

Description

@martinlippert

Spring Boot already supports the AOT Cache features of modern JVMs, especially when running in JDK 25 and beyond. We should use this for running the language server.

The JDK AOT Cache mechanism is a two-step process:

  1. training run (run the app, at shutdown, the JVM creates the cache data)
  2. subsequent runs (the app uses the cached data)

Since the training run has to use the exact same JVM on the exact same architecture as the subsequent runs, we can't create the cache file during build time and ship it with the language server. Instead, we need to do all this on the users machine in the background. But since we control the logic that starts up the language server process when running the Spring Tools, we can do (in the launch logic of the language server):

  • start the language server process in training run mode when there is no cache file around yet
  • start the language server with the cache settings if the cache file is around

Training mode is enabled via: -XX:AOTCacheOutput=app.aot
Cache usagem mode is enabled via: -XX:AOTCache=app.aot

(assuming that the app.aot is the name of the cache file, we should probably use a more specific one for your case)

Before we enable those options, we need to verify that the language server runs on a JDK >= 25. If not, we do not enable those options. Once we move the minimum requirement to run the language server up to JDK 25, we can always run those options, of course. But at the moment, the language server can still run on a JDK 21.

Updating the cache: Since the language server install directory is a fresh one every time an update of the language server is installed, we don't need to worry about outdated cache files - as long as the cache file is located next to the language server JAR. The only case we need to track here is whether the cache file was created using the exact same JVM - since that can be changed anytime.

Activity

  1. added this to the 5.1.0.RELEASE milestone on Feb 6, 2026
  2. added
    for: eclipse
    for: vscode
    on Feb 6, 2026
  3. martinlippert commented on Feb 6, 2026

    @martinlippert
    MemberAuthor

    Btw, early measurements show that the startup time of the language server is cut into less than half using this cache mechanism... 🥳

  4. martinlippert commented on Feb 6, 2026

    @martinlippert
    MemberAuthor

    Early experiments show messages regarding JDT core classes being skipped due to signed JAR files, we need to investigate this further, but that should not prevent us from enabling this. The nice startup performance improvements can be achieved nevertheless. But further improvements in this space might need to solve this.

  5. martinlippert commented on Mar 3, 2026

    @martinlippert
    MemberAuthor

    Early experiments show messages regarding JDT core classes being skipped due to signed JAR files, we need to investigate this further, but that should not prevent us from enabling this. The nice startup performance improvements can be achieved nevertheless. But further improvements in this space might need to solve this.

    Moved the additional improvements to a separate issue: #1824

  6. BoykoAlex commented on Mar 3, 2026

    @BoykoAlex
    Contributor

    I have been only having aot warnings about spring-core.7.0.2.jar... I had to turn that logging off... Redirecting to stederr din't help for some reason... AI blamed logback and spring-boot logging redirects for that.

  7. BoykoAlex commented on Mar 4, 2026

    @BoykoAlex
    Contributor

    @martinlippert Where do you think the preferences for enabling CDS be? Currently it is on the Spring -> Logs page...

  8. martinlippert commented on Mar 4, 2026

    @martinlippert
    MemberAuthor

    @martinlippert Where do you think the preferences for enabling CDS be? Currently it is on the Spring -> Logs page...

    I think having the preference directly in the main category should be fine. Looks like we have some of those preferences that don't have another home there... 😀

  9. martinlippert commented on Mar 4, 2026

    @martinlippert
    MemberAuthor

    @martinlippert Where do you think the preferences for enabling CDS be? Currently it is on the Spring -> Logs page...

    I think having the preference directly in the main category should be fine. Looks like we have some of those preferences that don't have another home there... 😀

    I've seen now that you renamed the title of the logs preference page to be more general around the language server, which seems to be fine with me as well. Let's go with that and ignore my previous comment.

  10. martinlippert commented on Mar 5, 2026

    @martinlippert
    MemberAuthor

    This doesn't seem to work yet on the VSCode side. The aot cache file is produced after the first run, but it isn't taken into account for subsequent runs. Instead, the language server VM is started with -XX:AOTCacheOutput=.... again, which produces a new aot cache file, but doesn't take the existing into account at startup.

  11. martinlippert commented on Mar 5, 2026

    @martinlippert
    MemberAuthor

    In contrast, the latest Eclipse-based snapshot builds work perfectly well (and I see the impressing startup speed improvements) 🚀

  12. martinlippert commented on Mar 9, 2026

    @martinlippert
    MemberAuthor

    Ships as part of the 5.1.0 release as an early-access experimental feature. Further improvements will be part of future releases.

    The short summary of what is implemented for 5.1.0 is:

    • a preference where users can enable this (disabled by default)
    • when running inside of Eclipse on a JDK 25 (with the preference enabled), the first run after install is configured as the training run. Shutting down Eclipse triggers the generation of the cache and subsequent starts on the same JDK will use the AOT cache automatically.
    • the Spring Tools for Eclipse distribution from https://spring.io/tools ships with JDK 25 by default, but the Eclipse packages from eclipse.org do not yet include a JDK 25 by default. So in case of using Spring Tools installed into a standard Eclipse package requires the user to upgrade the embedded JDK or to configure Eclipse to run on a different (Java 25) JDK than the embedded one.
    • the extensions for VSCode, Cursor, and Theia also include this feature, but creating the AOT cache requires a little extra work from the user. When installing and starting the extension for the first time on a JDK 25 (with the preference for this feature enabled), the language server runs the JDK in AOT training mode. After about 10min, a popup comes up that allows the user to explicitly finish the training run (and therefore create the real AOT cache) via a button in the popup. Hitting the button causes the VSCode window to be reloaded and the cache file to be created. Shutting down VSCode the usual way might result in no AOT cache file, due to the JVM being terminated without having the chance to create the cache file. Therefore, users who want to experiment with this early-access feature can use the popup and the embedded button to explicitly create the cache file. Once that is done, subsequent startups of the language server will use the AOT cache with a significant startup performance improvements automatically and can continue to shutdown VSCode the usual way again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

for: eclipsefor: vscodetheme: performancetype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions