Backend Development 16 min read

Optimizing Spring Application Startup Speed and Performance: Analysis, Tools, and Best Practices

This article explores the challenges of slow Spring application startup in large Java projects, presents detailed analysis techniques, visualizations, and a suite of tools—including Spring Startup Analyzer, Arthas, and Async Profiler—to identify bottlenecks, and provides step‑by‑step optimization methods such as bean lazy loading, jar slimming, and configuration tweaks that can reduce startup time by up to 80% while improving resource utilization and deployment efficiency.

JD Tech
JD Tech
JD Tech
Optimizing Spring Application Startup Speed and Performance: Analysis, Tools, and Best Practices

As Java developers increasingly rely on the Spring framework for large‑scale applications, startup speed and performance become critical concerns. This article delves into professional analysis and optimization techniques that dramatically improve Spring application launch times and runtime efficiency, addressing development bottlenecks and rapid scaling needs.

Current Situation and Background

Spring is a widely used Java framework, but its complexity and extensive dependencies can lead to long startup times—often minutes for large JAR bundles—hindering developer productivity and slowing down fault‑tolerance scaling.

Optimizing startup involves analyzing initialization processes, removing unnecessary dependencies, and leveraging asynchronous initialization and lazy loading to enhance developer efficiency, reduce debugging time, and improve user experience.

Main Content

Spring Bean Loading Timeline Visualization (✅)

Spring Bean Dependency Visualization (✅)

Unused JAR Detection (✅)

Application Startup Thread Wall‑Clock Flame Graph (✅)

Importance and Impact

Improved development efficiency by reducing startup and debugging cycles.

Faster deployment and scaling, lowering time and cost of bringing services online.

Optimized resource utilization, decreasing memory and CPU consumption.

Analysis Tools

Arthas – real‑time Java diagnostics.

JVM Sandbox – isolates and limits Java access permissions.

Async Profiler – low‑overhead asynchronous performance profiling.

Spring Boot Startup Report – detailed bean loading and auto‑configuration timings.

Jaeger UI – distributed tracing visualization.

Spring Startup Analyzer – interactive startup data collection and HTML reports.

Startup Overview

Key metrics include startup time (seconds), number of beans, used/total JARs, unused/total JARs, and classloader count. Visualizations such as timeline charts and flame graphs help pinpoint slow components.

Flame Graph Interpretation

The Y‑axis shows the call stack; the X‑axis represents sample counts (not absolute time). Wide sections indicate functions that consume significant CPU, and plateaus suggest potential performance issues.

Implementation and Optimization Results

After applying the following optimizations, startup time was reduced by 70‑80%:

Enabled bean lazy loading (including ES beans) – reduced time to ~131 s.

Removed unused JARs – decreased compilation and startup overhead.

Optimized slow beans (e.g., JSF registry retries) – reduced time to ~185 s.

Applied global lazy loading where appropriate, noting potential risks in production Kubernetes environments.

Installation and Configuration

Manual Installation

mkdir -p ${HOME}/spring-startup-analyzer
# 下载路径替换为实际路径
tar -zxvf spring-startup-analyzer.tar.gz -C ${HOME}/spring-startup-analyzer

Script Installation (Linux/macOS)

curl -sS https://raw.githubusercontent.com/linyimin0812/spring-startup-analyzer/main/bin/install.sh | sh

Default script installation path: $HOME/spring-startup-analyzer

Application Startup

Spring Startup Analyzer runs as a Java agent. Add the following JVM argument when launching the application:

java -javaagent:/Users/runner/spring-startup-analyzer/lib/spring-profiler-agent.jar \
    -Dproject.name=mac-demo \
    -Dspring-startup-analyzer.admin.http.server.port=8066 \
    -jar /Users/runner/spring-startup-analyzer/ARK.jar

In IDEs (e.g., IntelliJ IDEA), add the same agent path to the VM options.

Configuration Files

Example XML snippet to adjust a JSF registry that caused long retries:

Update the host file to resolve the registry address, e.g.:

*.*.*.* 注册中心地址

Performance Improvements

Before optimization, the pre‑release environment required ~10 minutes to start, with 585 JARs (337 unused). After optimization:

Local development startup reduced to ~2 min 11 s (Intel) or ~90 s (M1).

Pre‑release deployment time shortened dramatically, enabling faster iteration.

Overall startup efficiency improved by 70‑80%.

Key Optimization Strategies

Remove unused JARs after careful verification.

Identify and lazily load slow beans.

Disable unnecessary services (e.g., JSF publishing) in local environments.

Enable global lazy loading where safe.

Split large components to load only required parts.

Use profiling tools (Spring Startup Analyzer, Async Profiler, VisualVM) to locate bottlenecks.

Regularly refactor code, optimize algorithms, and employ caching.

Parallelize independent tasks with multithreading or async mechanisms.

Additional Resources

Oracle JDK 8 download: https://www.oracle.com/java/technologies/downloads/#java8-mac

Local Redis installation guide: https://redis.io/docs/install/install-redis/install-redis-on-windows/

Spring Startup Analyzer repository: https://github.com/linyimin0812/spring-startup-analyzer

Summary: Optimization Key Points and Methods

By systematically analyzing startup timelines, visualizing bean dependencies, slimming unused JARs, and applying lazy loading, developers can achieve substantial reductions in Spring application startup time, improve resource efficiency, and accelerate development cycles.

backendPerformancestartup optimizationSpringprofilinglazy-loading
JD Tech
Written by

JD Tech

Official JD technology sharing platform. All the cutting‑edge JD tech, innovative insights, and open‑source solutions you’re looking for, all in one place.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.