At fisrt load into browser response is very slow. Set ExtractingRoot as context ressources fix this issue by pre-extracting the resources. Maybe this commit can be linked this issue #6177

Comment From: pivotal-cla

@dlemaignent Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

Comment From: pivotal-cla

@dlemaignent Thank you for signing the Contributor License Agreement!

Comment From: dlemaignent

Note : to reproduce issue you need to launch spring boot web application with a war package set as executable (./my_app.war)

Comment From: wilkinsona

Thanks for the suggestion.

At fisrt load into browser response is very slow. Set ExtractingRoot as context ressources fix this issue

Can you please provide a minimal sample application that illustrates the difference?

Maybe this commit can be linked this issue https://github.com/spring-projects/spring-boot/issues/6177

Our belief is that https://github.com/spring-projects/spring-boot/issues/6216 accounts for much of the difference when running a war. A sample application that illustrates the problem you're facing will help us to see if that's not the case.

Note : to reproduce issue you need to launch spring boot web application with a war package set as executable (./my_app.war)

Looking at Tomcat's code, I cannot see why it would not also reproduce when running with java -jar my_app.war. Again, a sample application will help us to understand exactly what's happening.

Comment From: dlemaignent

Thanks for your quick response.

I've created this repo https://github.com/dlemaignent/first-war-start-slow to reproduce the issue.

I confirm that the application can be launched with java -jar my_app.war , the issue is the same.

Comment From: wilkinsona

Thanks, @dlemaignent. I'm seeing a significant difference in startup time with ./mvnw spring-boot:run (3.078s) vs java -jar (8.561s):

2022-03-10 15:14:02.082  INFO 64384 --- [  restartedMain] c.e.f.FirstWarStartSlowApplication       : Started FirstWarStartSlowApplication in 3.078 seconds (JVM running for 3.544)
2022-03-10 15:15:24.511  INFO 64501 --- [           main] c.e.f.FirstWarStartSlowApplication       : Started FirstWarStartSlowApplication in 8.561 seconds (JVM running for 9.487)

Switching to Undertow, the difference is much less pronounced:

2022-03-10 15:25:40.502  INFO 68556 --- [  restartedMain] c.e.f.FirstWarStartSlowApplication       : Started FirstWarStartSlowApplication in 2.893 seconds (JVM running for 3.343)
2022-03-10 15:19:44.830  INFO 68316 --- [           main] c.e.f.FirstWarStartSlowApplication       : Started FirstWarStartSlowApplication in 4.61 seconds (JVM running for 5.209)

Switching back to Tomcat but with jar packaging, it is significantly quicker with performance that is similar to Undertow's:

2022-03-10 15:27:43.556  INFO 69563 --- [           main] c.e.f.FirstWarStartSlowApplication       : Started FirstWarStartSlowApplication in 4.739 seconds (JVM running for 5.265)

There's obviously work to do here so that Tomcat starts quickly when packaged as a war. However, I don't think that extracting by default should be the answer. It would mean that changing packaging alters the runtime behaviour in terms of how the application writes to the filesystem and I think that might catch a lot of people out. I'd prefer that we find a way to close the performance gap without making a functional change. In the meantime, you can opt in as you have done using a customizer. Thanks anyway for the suggestion.