10 Proven Spring Boot 3 Performance Tweaks to Supercharge Your Apps

Discover ten validated Spring Boot 3 performance optimization techniques—including lazy initialization, JVM tuning, connection pooling, caching, async processing, virtual threads, and Actuator monitoring—complete with configuration snippets and code examples, to accelerate startup, reduce memory usage, and improve response times for Java backend services.

Spring Full-Stack Practical Cases
Spring Full-Stack Practical Cases
Spring Full-Stack Practical Cases
10 Proven Spring Boot 3 Performance Tweaks to Supercharge Your Apps

1. Introduction

Spring Boot is the most popular Java application framework, but without proper optimization it may suffer from slow startup, high memory consumption, slow database queries, and long response times under high load.

2. Optimization Tips

2.1 Enable Lazy Initialization

Lazy initialization delays bean creation until they are needed, improving startup time. Add the following configuration:

spring:
  main:
    lazy-initialization: true

Note that missing beans will cause errors at runtime when accessed.

public class CCommonent { }

@Component
public class Pack {
  @Resource
  private CCommonent cc;
}

2.2 Reduce Unnecessary Auto‑Configuration

Disable unneeded auto‑configurations to speed up startup and reduce memory usage:

spring:
  autoconfigure:
    exclude: com.x.y.z.XxxAutoConfiguration

2.3 JVM Memory Optimization

Set the same initial and maximum heap size to avoid resizing, and enable appropriate garbage collectors:

# Set heap size
java -Xms2048m -Xmx2048m -jar pack_app.jar

# Enable G1 GC (default since Java 9)
java -XX:+UseG1GC -jar pack_app.jar

# For ultra‑low latency, use ZGC (available from Java 11)
java -XX:+UseZGC -jar pack_app.jar

2.4 Database Performance

Use a connection pool (e.g., HikariCP) and configure it:

spring:
  datasource:
    driverClassName: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/datajpa
    username: root
    password: root
    type: com.zaxxer.hikari.HikariDataSource
    hikari:
      minimumIdle: 100
      maximumPoolSize: 100
      autoCommit: true
      idleTimeout: 30000
      poolName: packCP
      maxLifetime: 1800000
      connectionTimeout: 30000
      connectionTestQuery: SELECT 1

Create indexes for frequently queried columns, preferably composite indexes:

# MySQL example
CREATE INDEX idx_product_name ON product (name);

Consider caching to reduce database calls.

2.5 Cache to Reduce DB Calls

Add Spring Cache dependency and enable caching:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-cache</artifactId>
</dependency>
@SpringBootApplication
@EnableCaching
public class App { }
@Cacheable("products")
public List<Product> getAllProducts() {
    return productRepository.findAll();
}

2.6 Optimize REST API

Enable GZIP compression to shrink response payloads:

server:
  compression:
    enabled: true
    mime-types: text/html,text/xml,text/plain,application/json

2.7 Asynchronous Processing for Time‑Consuming Tasks

Enable async support and annotate methods with @Async:

@EnableAsync
@SpringBootApplication
public class App { }

@Async
public CompletableFuture<String> processHeavyTask() {
    return CompletableFuture.supplyAsync(() -> "Task Completed");
}

2.8 Virtual Threads

Spring Boot 3 supports virtual threads. Define a bean returning a virtual‑thread executor:

@Bean
Executor taskExecutor() {
    return Executors.newVirtualThreadPerTaskExecutor();
}

Enable virtual threads in configuration:

spring:
  threads:
    virtual:
      enabled: true

2.9 Asynchronous Logging

Configure Logback to use an async appender:

<configuration>
  <appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
    <appender-ref ref="FILE"/>
  </appender>
</configuration>

2.10 Actuator Monitoring

Add the Actuator starter and expose health, info, and metrics endpoints:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
management:
  endpoints:
    web:
      exposure:
        include: health,info,metrics

Access /actuator/health to view application health.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaoptimizationConfigurationperformance tuningSpring Boot
Spring Full-Stack Practical Cases
Written by

Spring Full-Stack Practical Cases

Full-stack Java development with Vue 2/3 front-end suite; hands-on examples and source code analysis for Spring, Spring Boot 2/3, and Spring Cloud.

0 followers
Reader feedback

How this landed with the community

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.