Skip to content

Commit 3594b61

Browse files
brunoborgesCopilot
andcommitted
Add AOT cache support for generator fat JAR
- Add build-cds.sh script to create Java 25 AOT cache (~21MB) - AOT cache reduces warm time from 0.46s to 0.27s (~40% faster) - Add .gitignore entries for platform-specific cache files - Update README and BENCHMARK with AOT cache instructions and results Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent bb1b2ed commit 3594b61

File tree

4 files changed

+59
-7
lines changed

4 files changed

+59
-7
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ site/tooling/*.html
1212

1313
# Generated aggregate file (built from individual JSON sources by html-generators/)
1414
site/data/snippets.json
15+
16+
# Platform-specific CDS/AOT cache (generated by build-cds.sh)
17+
html-generators/generate.aot
18+
html-generators/generate.jsa
19+
html-generators/generate.classlist

html-generators/BENCHMARK.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,38 @@
11
# Generator Benchmarks
22

3-
Performance comparison of the three ways to run the HTML generator, measured on 85 snippets across 10 categories.
3+
Performance comparison of the four ways to run the HTML generator, measured on 85 snippets across 10 categories.
44

55
## Results
66

77
| Method | Cold Start | Warm Average | Notes |
88
|--------|-----------|-------------|-------|
9-
| **Fat JAR** (`java -jar`) | 1.72s | **0.46s** | Fastest warm; no JBang needed |
9+
| **Fat JAR + AOT** (`java -XX:AOTCache`) | 0.27s | **0.27s** | Fastest; requires one-time cache build |
10+
| **Fat JAR** (`java -jar`) | 1.72s | 0.46s | No setup needed |
1011
| **JBang** (`jbang generate.java`) | 0.96s | 0.77s | Includes JBang overhead |
1112
| **Python** (`python3 generate.py`) | 0.17s | 1.37s | Fastest cold start; slowest warm |
1213

1314
- **Cold start**: First run after clearing caches / fresh process
14-
- **Warm average**: Mean of 4 subsequent runs
15+
- **Warm average**: Mean of 4 subsequent runs (AOT: mean of 5, no cold penalty)
1516

1617
## Key Takeaways
1718

18-
- The **fat JAR** is the fastest option for repeated builds — **~40% faster** than JBang and **~3× faster** than Python at warm steady-state
19+
- The **fat JAR + AOT cache** is the fastest option — **~40% faster** than the plain fat JAR and **~5× faster** than Python
20+
- The AOT cache eliminates the JVM cold start penalty entirely (0.27s cold = 0.27s warm)
1921
- **Python** has the fastest cold start (no JVM boot) but is the slowest overall
2022
- **JBang** adds ~0.3s overhead vs the fat JAR due to its launcher and cache lookup
21-
- For CI/CD, the fat JAR is ideal — no JBang installation or dependency caching required
23+
- For CI/CD, the plain fat JAR is ideal — no AOT build step needed, and still very fast
24+
25+
## AOT Cache Setup
26+
27+
```bash
28+
# One-time: build the cache (~21 MB, platform-specific)
29+
./html-generators/build-cds.sh
30+
31+
# Use it
32+
java -XX:AOTCache=html-generators/generate.aot -jar html-generators/generate.jar
33+
```
34+
35+
The AOT cache uses Java 25 CDS (JEP 514/515) to pre-load ~3,300 classes from a training run. It is platform-specific (CPU arch + JDK version) and not committed to git.
2236

2337
## Environment
2438

html-generators/README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This folder contains the build scripts that generate all HTML detail pages and `
99
| `generate.java` | JBang script (Java 25) — primary generator |
1010
| `generate.py` | Python equivalent — produces identical output |
1111
| `generate.jar` | Pre-built fat JAR (no JBang/JDK setup needed) |
12+
| `build-cds.sh` | Script to build a platform-specific AOT cache |
1213

1314
## Running
1415

@@ -20,15 +21,27 @@ java -jar html-generators/generate.jar
2021

2122
Requires only a Java 25+ runtime — no JBang installation needed.
2223

23-
### Option 2: JBang (for development)
24+
### Option 2: Fat JAR with AOT cache (fastest possible)
25+
26+
```bash
27+
# One-time: build the AOT cache (~21 MB, platform-specific)
28+
./html-generators/build-cds.sh
29+
30+
# Subsequent runs use the cache
31+
java -XX:AOTCache=html-generators/generate.aot -jar html-generators/generate.jar
32+
```
33+
34+
The AOT cache (Java 25, JEP 514/515) pre-loads classes from a training run, reducing startup time by ~30%. The cache is platform-specific and is not committed to git — regenerate it after changing the JAR or JDK version.
35+
36+
### Option 3: JBang (for development)
2437

2538
```bash
2639
jbang html-generators/generate.java
2740
```
2841

2942
Requires [JBang](https://jbang.dev) and Java 25+.
3043

31-
### Option 3: Python
44+
### Option 4: Python
3245

3346
```bash
3447
python3 html-generators/generate.py

html-generators/build-cds.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
# Build an App CDS / AOT cache for the generator fat JAR.
3+
# The cache is platform-specific and must be regenerated when
4+
# the JAR or JDK version changes.
5+
#
6+
# Usage:
7+
# ./html-generators/build-cds.sh # creates generate.aot
8+
# java -XX:AOTCache=html-generators/generate.aot -jar html-generators/generate.jar
9+
10+
set -euo pipefail
11+
cd "$(git rev-parse --show-toplevel)"
12+
13+
JAR="html-generators/generate.jar"
14+
AOT="html-generators/generate.aot"
15+
16+
echo "Training run + AOT cache generation..."
17+
java -XX:AOTCacheOutput="$AOT" -jar "$JAR"
18+
echo "Done: $AOT ($(du -h "$AOT" | cut -f1))"
19+
echo ""
20+
echo "Run with: java -XX:AOTCache=$AOT -jar $JAR"

0 commit comments

Comments
 (0)