fbpx

Revolutionize JVM Startup Times with Class Data Sharing (CDS)

                                <p dir="ltr"><span>The digital landscape is constantly changing. This makes efficiency more vital than ever and optimizing Java Virtual Machine (JVM) startup times a pressing concern. This is where Class Data Sharing (CDS) comes into play—a frequently underestimated yet groundbreaking feature poised to enhance JVM startup efficiency significantly.</span></p>

Understanding Class Data Sharing (CDS)

Class Data Sharing (CDS) isn’t a new concept in the Java ecosystem, but its potential has long been underappreciated. Originally introduced to improve startup performance by sharing class data between Java Virtual Machines, CDS seemed to fly under the radar for years. However, recent developments have brought this powerful tool back into the spotlight.

What is CDS?

CDS allows a JVM to create a shared archive of class metadata, which can then be reused across different JVM instances. This process involves a “training run” that pre-processes what your application will need at runtime, allowing subsequent startups to bypass certain class loading and initialization steps and  significantly reducing startup times.

The resurgence of CDS

Although support for CDS in Java dates back almost six years, we’ve seen a resurgence in its interest and development. This renewed focus is largely driven by the Java team’s ongoing efforts under Project Leyden, which is aimed at making CDS more effective and accessible.

Developers following the efficiency features in Spring Boot 3 releases will have seen GraalVM native image support arrive in 3.0 and initial support for CRaC (Coordinated Restore at Checkpoint) arrive in 3.2. There are pros and cons to each technology, however the new CDS support offers a low barrier to entry and enables application startup efficiency gains with very little effort. This is what makes it so exciting.

The Catalyst—Spring Boot integration

Integrating support into Spring Boot brings CDS front and center to a massive audience of developers. By embedding CDS capabilities within Spring OSS, we laid the foundation for broader adoption, and community feedback has been overwhelmingly positive.

The new Spring Boot CDS-friendly layout extraction feature is a key piece of the puzzle, but developers still need to understand how to execute a training run and configure the subsequent starts to use the computed cache. There are multiple options for developers here, including Dockerfiles or Buildpacks. Building on Spring Boot support, we have already done the heavy lifting in the Java Buildpack—simply set an environment variable to execute the training run automatically, which will compute the optimized cache and use it when starting the application. Of course, this all works with VMware Tanzu Platform.

What’s in the OSS?

The OSS buildpack offers the basic building blocks to get started with CDS. It works for simple applications, but also requires additional configuration for enterprise-grade apps. When executing the training run to enable subsequent fast startup, it may fail if it attempts to connect to unavailable services during the build process. In Spring OSS, there are controls to prevent such connections during training, but these require manual configuration in the OSS Buildpack support. Commercial Buildpacks will handle these configurations automatically.

Tanzu Platform Commercial Buildpacks—The path forward

There is even more to come in Commercial Buildpacks, but enterprise application-grade CDS support is an exciting new feature that is available now.  This enhancement significantly enhances startup times and reduces memory consumption. The Commercial Buildpack simplifies the enablement of CDS by minimizing side effects, such as premature database interaction, and making the developer experience a simple flag to trigger activation. This marks the initial phase, with more to come.

Class Data Sharing (CDS) represents a significant step forward in optimizing JVM startup times, especially for enterprise applications. Spring Boot support brings it to a wide audience while enhanced Buildpack support enables easy adoption.

Content used for graphic: Pre-processing the requirements of your application before runtime enables quicker startups by skipping specific class loading and initialization steps, resulting in a 30% reduction in startup times

Together, we can unlock the full potential of Java and drive innovation in the digital age.