Cutting Memory Bloat: How Fusion’s Server‑Side Pagination Turns Huge Datasets Into Responsive UI
When Fusion apps pull 100,000+ rows in one request, memory spikes and UI freezes. Leverage Fusion’s server‑side pagination to keep memory low and response times fast. A quick guide with code, trade‑offs, and a practical checklist.
18 Jun 2026, 23:30 UTC

Problem: Massive Result Sets Kill Performance
When a Fusion app pulls 100,000+ rows into a single API response, the JVM spends hours serializing, the browser freezes, and the database is hammered with a single large query. Developers often resort to client‑side hacks like slicing arrays after download, which only shifts the memory pressure to the browser and hides the real bottleneck.
Thesis: Let Fusion’s PaginationService Do the Heavy Lifting
Fusion’s built‑in server‑side pagination abstracts the OFFSET/LIMIT dance into a declarative @Paginated annotation. By delegating paging to the database, you keep memory usage low, reduce latency, and expose a clean, reusable API for the front‑end.
1. Architecture: Separation of Concerns
Fusion’s architecture splits data access from presentation. The PaginationService lives in the service layer and accepts three parameters:
pageNumber– zero‑based index of the page requested.pageSize– how many items per page.sortBy– optional field names and directions.
The service then composes a SELECT … OFFSET … FETCH NEXT … ROWS ONLY clause, letting the RDBMS do the heavy lifting. The controller simply forwards the pagination parameters to the service and returns a Page<T> object that includes total count, current page, and the sliced data.
2. Implementation: A Minimal Code Example
Below is a typical pattern in a Fusion 3.2 project. Assume a User entity and a REST endpoint that serves paged user data.
// Repository layer
public interface UserRepository extends JpaRepository<User, Long> {
@Paginated
Page<User> findAllByActive(boolean active, Pageable pageable);
}
// Service layer
@Service
public class UserService {
@Autowired
private UserRepository repo;
public Page<User> listActiveUsers(int page, int size) {
Pageable pageable = PageRequest.of(page, size, Sort.by("lastName"));
return repo.findAllByActive(true, pageable);
}
}
// Controller
@RestController
@RequestMapping("/api/users")
public class UserController {
@Autowired
private UserService service;
@GetMapping("/active")
public ResponseEntity<Page<UserDTO>> getActiveUsers(
@RequestParam(defaultValue="0") int page,
@RequestParam(defaultValue="20") int size) {
Page<User> users = service.listActiveUsers(page, size);
Page<UserDTO> dtoPage = users.map(UserDTO::fromEntity);
return ResponseEntity.ok(dtoPage);
}
}
Key points:
- The
@Paginatedannotation tells Fusion to generate the correct SQL. - All paging logic lives in the service; the controller only handles HTTP parameters.
- DTO mapping is performed after the slice, so only the requested rows are materialized.
3. Trade‑offs and Limitations
- Latency per request: Each page requires a round‑trip to the database. For highly dynamic data, consider caching the counts or using key‑set pagination.
- Page size tuning: A size of 20–50 rows is safe for most databases; 500+ can overwhelm memory or cause long query plans.
- Database limits: Some engines cap the maximum
OFFSET. Verify your DB’s limits before choosing a large page number. - Client‑side caching: If the front‑end caches entire pages, pagination errors can be silent. Enable cache‑busting headers to surface issues early.
4. Actionable Checklist
- Enable Pagination – Add
@Paginatedto repository methods that return large sets. - Set Reasonable Defaults – In
application.ymlconfigurefusion.pagination.default-page-size: 20and expose an upper bound. - Verify SQL Generation – Use
EntityManager.unwrap(Session.class).doWork()to log the generated query and confirmOFFSET/FETCHusage. - Load‑Test – Run a JMeter or k6 script that requests page 0–10 with 100k rows. Check that response times stay <200 ms.
- Monitor – Add a metric for
fusion.pagination.requests.totalandfusion.pagination.requests.latencyto catch regressions. - Adjust Page Size – If latency spikes, reduce
pageSizeor switch to key‑set pagination for very large tables.
By following this pattern, you keep the JVM lean, the database under control, and the UI snappy. Fusion’s server‑side pagination is a proven, low‑friction solution for any app that must surface thousands of records.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.