Back to Java 24/25 Preview
Q8Question 8 of 8

What is Project Leyden?

Key Concepts
  • Project Leyden dramatically reduces JVM startup time by performing class loading, linking, and JIT compilation ahead of time
  • CDS (Class Data Sharing) dumps pre-parsed class metadata into a shared archive that is memory-mapped at startup
  • AppCDS extends CDS to application classes, reducing startup by 20-40 percent
  • Leyden adds pre-resolved constant pools, pre-linked classes, and AOT-compiled hot methods
  • Targets sub-100ms startup for Spring Boot applications versus 2-5 seconds without optimization
  • Critical for serverless (AWS Lambda cold starts) and Kubernetes scale-to-zero deployments
  • Unlike GraalVM native image, Leyden preserves full JVM capabilities including dynamic class loading and reflection

Definition

Project Leyden reduces JVM startup from seconds to under 100 milliseconds by pre-computing class loading, linking, and JIT compilation ahead of time into a shared archive.
  • JVM startup problem – class loading, bytecode verification, linking, and JIT compilation happen on every start, taking 2-5 seconds for Spring Boot applications.
  • CDS (Class Data Sharing) – dumps pre-parsed class metadata into a .jsa archive that is memory-mapped at startup, saving 20-40% startup time.
  • Project Leyden – extends CDS with pre-resolved constant pools, pre-linked classes, and AOT-compiled hot methods, targeting sub-100ms startup.
  • Use case – serverless functions (AWS Lambda cold starts), Kubernetes scale-to-zero, CLI tools, and any workload where startup time matters.
  • Advantage over GraalVM – preserves full JVM: dynamic class loading, reflection, proxy generation, and all Spring Boot features work without closed-world constraints.

Every time the bank opens a temporary branch (JVM starts), clerks must unpack boxes (class loading), read the policy manual (bytecode verification), and practice procedures (JIT warm-up). Project Leyden pre-prepares everything: manuals are pre-printed (CDS archive), procedures are pre-rehearsed (AOT compilation), and boxes are pre-unpacked (pre-linking). A new branch opens in under 100 milliseconds instead of 5 seconds.

Understanding the Concepts

What is Project Leyden?

Project Leyden aims to dramatically reduce JVM startup time by shifting expensive work from runtime to build time.

What makes JVM startup slow?

Four steps happen on every JVM start.

  1. Class loading: reads thousands of .class files from JAR files, parsing bytecode and building internal data structures.
  2. Bytecode verification: ensures loaded classes are valid and safe.
  3. Linking: resolves symbolic references between classes.
  4. JIT compilation: compiles hot methods to native code after sufficient profiling.

For a Spring Boot application, these steps take 2-5 seconds.

What is CDS (Class Data Sharing)?

CDS dumps pre-parsed class metadata into a shared archive file (.jsa). At startup, the JVM memory-maps this archive instead of loading classes from JARs.

BASH
# Step 1: Create class list during a training run
java -Xshare:off -XX:DumpLoadedClassList=classes.lst -jar bank-service.jar

# Step 2: Dump the CDS archive
java -Xshare:dump -XX:SharedClassListFile=classes.lst \
     -XX:SharedArchiveFile=app.jsa -jar bank-service.jar

# Step 3: Run with the pre-computed archive
java -Xshare:on -XX:SharedArchiveFile=app.jsa -jar bank-service.jar
TEXT
Without CDS: 2500ms startup
With CDS:    1500ms startup (40% faster)

How does Leyden go further?

Leyden adds three optimizations beyond CDS.

  • Pre-resolved constant pools: method and field references are resolved once during the training run and cached.
  • Pre-linked classes: class hierarchy verification is done once and cached.
  • AOT-compiled code: frequently called methods are compiled to native code ahead of time.
DIAGRAM
CDS only:       2500ms → 1500ms
Leyden target:  2500ms → 100ms (sub-100ms!)

Why does this matter for serverless?

| Deployment | Without CDS | With CDS | Leyden Target |
|---|---|---|---|
| Spring Boot startup | 2500ms | 1500ms | <100ms |
| AWS Lambda cold start | 5000ms | 3000ms | <500ms |
| K8s scale-to-zero | 5000ms | 3000ms | <200ms |

For serverless functions that start, run for 200ms, and die, a 5-second cold start is unacceptable. Leyden makes Java competitive with Go and Node.js for cold-start latency.

How is Leyden different from GraalVM native image?

| Aspect | GraalVM Native Image | Project Leyden |
|---|---|---|
| Startup | 50-200ms | Target <100ms |
| JVM features | Limited (closed world) | Full JVM |
| Reflection | Requires configuration | Works natively |
| Dynamic class loading | Not supported | Supported |
| Spring Boot support | Requires native hints | Full support |
| Build time | Minutes | Seconds |

Leyden preserves the full JVM, so dynamic class loading, reflection, proxy generation, and all Spring Boot features work without closed-world constraints or explicit configuration.

What should a senior engineer know?

  • Spring Boot 3.3+ has built-in CDS support via spring-boot:build-image.
  • The training run must capture representative workload; the archive is suboptimal if usage patterns differ significantly in production.
  • CDS archives are JDK-version-specific: rebuild when upgrading the JDK.
  • Leyden is an ongoing OpenJDK project; features are being delivered incrementally across JDK releases.

What are common interview follow-up questions?

  • Can I use CDS today? (Yes. CDS is available in all modern JDKs. AppCDS for application classes is available since JDK 10.)
  • Does Leyden replace GraalVM? (No. GraalVM native image may still be faster for specific cold-start scenarios. Leyden targets the mainstream JVM path.)
  • What is the trade-off? (A build-time training run is required to generate the archive, which is bundled into the Docker image.)

Visual Overview

DIAGRAM
  JVM Startup Optimization:

  Standard JVM Start (2500ms):
  ┌─────────┐  ┌────────┐  ┌───────┐  ┌─────┐
  │ Class   │─▶│Verify  │─▶│ Link  │─▶│ JIT │─▶ Ready
  │ Loading │  │Bytecode│  │Classes│  │Warm │
  │ (1000ms)│  │(300ms) │  │(200ms)│  │(1s) │
  └─────────┘  └────────┘  └───────┘  └─────┘

  With CDS (1500ms):
  ┌─────────────────┐  ┌───────┐  ┌─────┐
  │ Memory-map .jsa │─▶│ Link  │─▶│ JIT │─▶ Ready
  │ (100ms)         │  │(200ms)│  │(1s) │
  └─────────────────┘  └───────┘  └─────┘

  With Leyden (<100ms target):
  ┌──────────────────────────────────────┐
  │ Memory-map archive (pre-loaded,      │
  │ pre-linked, pre-compiled)            │─▶ Ready!
  │ (<100ms)                             │
  └──────────────────────────────────────┘

Key Takeaway

Project Leyden aims to reduce JVM startup from seconds to under 100 milliseconds by performing class loading, linking, and JIT compilation ahead of time. CDS (Class Data Sharing), available today, pre-parses class metadata into a shared archive that is memory-mapped at startup, saving 20-40% of startup time. Leyden extends this with pre-resolved constant pools, pre-linked classes, and AOT-compiled hot methods.

The impact is most dramatic for serverless and cloud-native workloads. An AWS Lambda cold start for a Spring Boot application drops from 5 seconds to under 500 milliseconds. Kubernetes scale-to-zero pods start in under 200 milliseconds instead of 5 seconds. This makes Java competitive with Go and Node.js for cold-start latency while preserving the full JVM ecosystem.

Unlike GraalVM native image, Leyden preserves all JVM capabilities: dynamic class loading, reflection, proxy generation, and all Spring Boot features work without closed-world constraints or explicit configuration. The trade-off is a build-time training run to generate the optimized archive.

Remember one sentence: Project Leyden reduces JVM startup to under 100 milliseconds by pre-computing class loading, linking, and JIT compilation into a shared archive.

---

Share
Use ← → arrow keys to navigate