I'm working on a Spring Boot + Kotlin application and want to speedup the bootRun startup and devtools restart time. The restart currently takes around 20-30 seconds which feels painfully slow compared to the near-instant refresh of frontend changes when hot-reloading is possible.
I'm using macOS Big Sur 11.6.7 with the Amazon corretto 17 JDK
1. Update local hostname in
/etc/hostson macOSI found that there was consistently a nearly exactly 5 second delay during the application restart with devtools even on an empty project. I asked about this here: What is happening after Spring Boot Devtools logs "Starting application" and ultimately found that this was due to a hostname resolution issue with the JVM on macOS. The solution as described there is:
hostname-> egMonroes-MacBook-Pro.localsudo vim /etc/hosts2. Use a trigger file for devtools
Initially I had IntelliJ auto rebuild the project which would result in devtools detecting changes to the class files, but this would often result in multiple restarts for one set of changes as mentioned here: DevTools restarts twice in Intellij. Rather than auto rebuilding in IntelliJ and having devtools watch the whole project, I did the following:
build.gradle.kts
3. Update Gradle props to enable daemon, parallel builds, cache, and max heapsize
gradle.properties
4. Enable gradle configuration caching (experimental / unstable)
Explained in the Gradle docs here gradle.properties
5. Other changes
The changes above had the biggest impact for me, but here are some other pages and recommendations. Pages:
Things to try :
spring.main.lazy-initialization=true. Bean initialization will be delayed until their first use.Other notes
For reference, the final turnaround time between making changes and having the application running and serving requests again is now 4 - 10 seconds on my computer. The compilation in IntelliJ takes 2-6 seconds and the application restart consistently takes ~2 seconds.
Related links