spring-performance · kyy-logs, code-review-gate — Claude Code rule: what it does, how to install
The spring-performance Claude Code rule sets Spring/JPA and performance checks. It flags issues in validation, transactions, queries, and batch operations.
MIT ★ 517 updated 2026-11-16
.claude/rules/spring-performance.mdWhat spring-performance does
The rule guides reviews of Spring and JPA code. It checks request validation with @Valid, transaction boundaries, and centralized exception handling through @RestControllerAdvice. For entity relationships, it calls out N+1 queries and points to JOIN FETCH or EntityGraph as alternatives.
It also flags string concatenation inside loops and single-row inserts where batch operations are shown instead. Server guidance covers Linux and JVM settings, including ulimit -n 65535; the Linux default of 1024 file handles is described as insufficient. In Claude Code, place the rule at .claude/rules/spring-performance.md.
What it helps with
- catch missing validation on Spring request parameters
- review transaction boundaries in service methods
- spot N+1 queries when loading related entities
- replace per-record inserts with batch operations
- find repeated string concatenation inside loops
Example prompts for the agent
- Review my Spring controllers for missing request validation.
- Find N+1 queries in the JPA code and suggest a fix.
- Check the services for transaction and batch-insert issues.
How to install spring-performance
Manually: put the files in place
.claude/rules/spring-performance.mdThe paths frontmatter field limits the files
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.cursor/rules/spring-performance.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/spring-performance.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/spring-performance.mdManually: put the files in place
.clinerules/spring-performance.mdStep by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use
Questions about spring-performance
How do I install spring-performance in Claude Code?
Place the rule file in the project at .claude/rules/spring-performance.md.
What does spring-performance do?
It guides Spring/JPA reviews, covering request validation, transaction handling, N+1 queries, string creation, and batch operations.
What does spring-performance check in JPA queries?
It flags N+1 query patterns when loading related entities and points to JOIN FETCH or EntityGraph.
Source text
spring-performance.md · MIT
# Spring/JPA and performance guidelines
## Spring/JPA best practices
### Parameter validation
**Detection mode**: semantic
```java
// Correct: validate with @Valid
@PostMapping("/users")
public UserDTO createUser(@Valid @RequestBody UserCreateRequest request) {
return userService.create(request);
}
@Data
public class UserCreateRequest {
@NotBlank(message = "username must not be blank")
@Size(min = 2, max = 50, message = "username length must be 2-50")
private String name;
@Email(message = "invalid email format")
private String email;
@Min(value = 0, message = "age must not be negative")
private Integer age;
}
```
### Transaction management
**Detection mode**: semantic
```java
// Correct: explicit transaction scope
@Transactional(rollbackFor = Exception.class)
public void createUser(User user, UserProfile profile) {
userDao.insert(user);
profile.setUserId(user.getId());
profileDao.insert(profile);
}
// Note: read-only operations should not use a transaction, or should use a read-only transaction
@Transactional(readOnly = true)
public User getUser(Long id) {
return userDao.findById(id);
}
```
### N+1 query prevention
**Detection mode**: semantic
```java
// Wrong: N+1 queries
List<User> users = userDao.findAll();
for (User user : users) {
List<Order> orders = orderDao.findByUserId(user.getId()); // N queries!
user.setOrders(orders);
}
// Correct: use JOIN FETCH
@Query("SELECT u FROM User u LEFT JOIN FETCH u.orders WHERE u.id IN :ids")
List<User> findWithOrders(@Param("ids") List<Long> ids);
// Or use EntityGraph
@Entity
@NamedEntityGraph(name = "User.withOrders",
attributeNodes = @NamedAttributeNode("orders"))
public class User { ... }
```
### Unified exception handling
**Detection mode**: semantic
```java
// Unified exception handling
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(BusinessException.class)
public ResponseEntity<ErrorResponse> handleBusiness(BusinessException e) {
return ResponseEntity.badRequest()
.body(new ErrorResponse(e.getCode(), e.getMessage()));
}
@ExceptionHandler(Exception.class)
public ResponseEntity<ErrorResponse> handleOther(Exception e) {
log.error("Unexpected error", e);
return ResponseEntity.internalServerError()
.body(new ErrorResponse("SYSTEM_ERROR", "system error"));
}
}
```
## Performance guidelines
### Server configuration
**Detection mode**: semantic
| Setting | Description | Recommended value |
|-------|------|-------|
| TCP time_wait timeout | Lower it in high-concurrency scenarios | `net.ipv4.tcp_fin_timeout=30` |
| Maximum file handles | The Linux default of 1024 is insufficient | `ulimit -n 65535` |
| JVM HeapDump | Generate a heap dump on OOM | `-XX:+HeapDumpOnOutOfMemoryError` |
### Object creation
**Detection mode**: semantic
```java
// Wrong: create strings in a loop
String result = "";
for (String item : list) {
result += item + ","; // creates a new String each time!
}
// Correct: use StringBuilder
StringBuilder sb = new StringBuilder();
for (String item : list) {
if (sb.length() > 0) sb.append(",");
sb.append(item);
}
String result = sb.toString();
// Or use String.join
String result = String.join(",", list);
```
### Batch operations
**Detection mode**: semantic
```java
// Wrong: one insert per iteration
for (User user : users) {
userDao.insert(user); // N IOs!
}
// Correct: batch insert
userDao.batchInsert(users);
```
© kyy-logs · MIT · kyy-logs/code-review-gate-skill
Similar IDE rules
All IDE rules for Backend and APIs →spring-performance by other authors comes first.