How to Speed Up Spring Boot Startup: 15 Optimizations Tested
The article documents a series of Spring Boot 2.1 startup benchmarks on OpenJDK 11, exploring fifteen different tweaks—from using WebFlux instead of WebMVC to enabling AppCDS and disabling unnecessary libraries—showing how each change impacts launch time and culminating in a sub‑second startup.
This post reproduces the "How fast is Spring?" demo from Spring One 2018 and runs a custom JMH benchmark on a minimal Spring Boot 2.1.0.RELEASE application using OpenJDK 11. The baseline startup time is 2.938 ± 0.287 s/op.
1. FluxBaseline
A simple Reactive Web controller is created with Spring Initializr. The benchmark result is 2.938 ± 0.287 s/op.
@SpringBootApplication
@RestController
public class DemoApplication {
@GetMapping("/")
public String home() { return "Hello"; }
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}2. WebMVC
Replacing the Reactive controller with a traditional WebMVC controller (Tomcat) yields 3.281 ± 0.342 s/op, slightly slower than the Flux baseline.
3. spring-context-indexer
Adding spring-context-indexer creates a component index. Benchmark: 3.063 ± 0.102 s/op, a small slowdown.
4. Lazy Initialization
Enabling lazy bean initialization reduces startup to 2.844 ± 0.129 s/op.
5. NoVerify
Running the JVM with -noverify improves the time to 2.582 ± 0.060 s/op.
6. TieredStopAtLevel
Using -XX:TieredStopAtLevel=1 dramatically speeds up launch to 1.980 ± 0.037 s/op.
7. Spring Config Location
Specifying -Dspring.config.location=classpath:/application.properties slows it to 3.026 ± 0.139 s/op.
8. Disable JMX
Disabling JMX with -Dspring.jmx.enabled=false yields 2.877 ± 0.097 s/op.
9. Remove Logback
Excluding Logback reduces startup to 2.904 ± 0.096 s/op.
10. Remove Jackson
Excluding the Jackson starter brings the time down to 2.789 ± 0.093 s/op.
11. Remove HibernateValidator
Excluding Hibernate Validator results in 2.857 ± 0.084 s/op.
12. AppCDS
Enabling Application Class Data Sharing (AppCDS) gives 2.957 ± 0.079 s/op, showing no improvement because Spring Boot fat JARs are not covered by CDS.
13. Thin Launcher (Exploded)
Packaging with the Spring Boot Thin Launcher (exploded layout) reduces launch time to 2.476 ± 0.091 s/op.
14. Thin Launcher + AppCDS
Combining Thin Launcher with AppCDS yields a significant gain: 1.535 ± 0.036 s/op.
15. All Optimizations Applied
Applying every previous tweak together results in a sub‑second startup: 0.801 ± 0.037 s/op.
The final benchmark table summarises all cases:
Benchmark Mode Cnt Score Error Units
MyBenchmark.case01_FluxBaseline ss 10 2.938 ± 0.287 s/op
MyBenchmark.case02_Web ss 10 3.281 ± 0.342 s/op
MyBenchmark.case03_WithContextIndexer ss 10 3.063 ± 0.102 s/op
MyBenchmark.case04_WithLazyInit ss 10 2.844 ± 0.129 s/op
MyBenchmark.case05_WithNoVerifyOption ss 10 2.582 ± 0.060 s/op
MyBenchmark.case06_WithTieredStopAtLevel1 ss 10 1.980 ± 0.037 s/op
MyBenchmark.case07_WithSpringConfigLocation ss 10 3.026 ± 0.139 s/op
MyBenchmark.case08_WithJmxDisabledOption ss 10 2.877 ± 0.097 s/op
MyBenchmark.case09_WithoutLogback ss 10 2.904 ± 0.096 s/op
MyBenchmark.case10_WithoutJackson ss 10 2.789 ± 0.093 s/op
MyBenchmark.case11_WithoutHibernateValidator ss 10 2.857 ± 0.084 s/op
MyBenchmark.case12_WithAppCds ss 10 2.957 ± 0.079 s/op
MyBenchmark.case13_Exploded ss 10 2.476 ± 0.091 s/op
MyBenchmark.case14_ExplodedWithAppCds ss 10 1.535 ± 0.036 s/op
MyBenchmark.case15_AllApplied ss 10 0.801 ± 0.037 s/opThese experiments demonstrate how various JVM flags, Spring Boot configuration choices, and dependency exclusions can collectively shrink Spring Boot startup time from nearly three seconds to under one second.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Backend Technology
Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
