Speed up Spring Boot startup time

The most voted answer so far is not wrong, but it doesn’t go into the depth I like to see and provides no scientific evidence. The Spring Boot team went through an exercise for reducing startup time for Boot 2.0, and ticket 11226 contains a lot of useful information. There is also a ticket 7939 open to adding timing information to condition evaluation, but it doesn’t seem to have a specific ETA.

The most useful, and methodical approach for debugging Boot startup has been done by Dave Syer. https://github.com/dsyer/spring-boot-startup-bench

I had a similar use case as well, so I took Dave’s approach of micro-benchmarking with JMH and ran with it. The result is the boot-benchmark project. I designed it such that it can be used to measure startup time for any Spring Boot application, using the executable jar produced by bootJar (previously called bootRepackage in Boot 1.5) Gradle task. Feel free to use it and provide feedback.

My findings are as follows:

  1. CPU matters. A lot.
  2. Starting the JVM with -Xverify:none helps significantly.
  3. Excluding unnecessary autoconfigurations helps.
  4. Dave recommended JVM argument -XX:TieredStopAtLevel=1, but my tests didn’t show significant improvement with that. Also, -XX:TieredStopAtLevel=1 would probably slow down your first request.
  5. There have been reports of hostname resolution being slow, but I didn’t find it to be a problem for the apps I tested.

Leave a Comment