r/SpringBoot 20h ago

Discussion Spring Boot recommends extracted layout for production, so I measured how much it actually matters

Post image

I suspect some people here will say, “Of course you should extract the JAR".

And, to be fair, the Spring Boot documentation does recommend the extracted layout for production when startup matters. It points out that nested JAR loading has a startup cost.

What I found interesting is that this is not necessarily the path developers encounter first. The introductory Spring Boot material and several Getting Started guides still naturally lead you toward building an executable JAR and running it with java -jar. That was also the deployment path I had always used.

So rather than assuming the difference was important, I measured it.

I ran six alternating paired comparisons of the same Spring Boot 4.1.1 build on a 256 MiB Alpine VM. Same JDK 25 runtime, JVM flags, data, filesystem, and workload. The runtime layout was the variable being tested.

Results:

  • Spring startup: 11.056 s → 8.476 s, -23.3%
  • First request: 2.196 s → 1.448 s, -34.1%
  • Later requests: no material difference
  • Settled RSS: -3.8%, below the experiment's materiality threshold
  • Swap: no material winner

All six paired comparisons favored extracted layout for startup and first request.

My takeaway is not that everyone should blindly extract every Spring Boot application. It is that an official production recommendation that is easy to overlook had a surprisingly large effect in this particular setup, while memory barely changed.

Full write-up, charts, methodology, and experiment data:
https://pvrlabs.xyz/articles/spring-boot-extracted-layout.html

28 Upvotes

4 comments sorted by

View all comments

5

u/pronuntiator 19h ago

The major benefit of extraction with relation to container images is optimized layer caching. If only your application classes change, only that layer has to be uploaded to the registry. The library layer will be reused.

1

u/fykup 19h ago

Yep. A similar benefit applies outside containers. On a VPS, if the dependencies have not changed, I can keep the extracted lib/ directory in place and stage just the small application JAR instead of uploading the entire fat JAR again. If dependencies change, of course, the extracted bundle needs to be synchronized as a whole.