Common performance anti-patterns in Liferay projects
After enough performance reviews, the slow portals start to look alike. The same anti-patterns appear project after project, usually introduced with good intentions and only becoming visible once data and traffic grow. Learning to spot them on sight is far more valuable than any single optimization, because it lets you prevent the problem instead of diagnosing it later.
Querying inside a loop
The classic N+1 problem: a query that runs once per item instead of once for the whole set. It is harmless in development with a handful of rows and crippling in production with thousands. The fix is almost always to fetch in bulk and resolve in memory.
// Anti-pattern: one query per row
for (long id : ids) {
results.add(service.fetchEntry(id));
}
// Better: a single query for all ids
results = service.fetchEntries(ids);Disabling caching to fix a stale-data bug
A common shortcut: a developer hits a stale-data issue, disables the entity cache to make it go away, and never re-enables it. The symptom disappears and the portal silently loses one of its biggest performance features. The right fix is correct cache invalidation, not turning caching off.
More anti-patterns to watch for
Beyond those two, a recurring set of mistakes shows up across projects:
- Loading full entities when only an ID or a count is needed.
- Synchronous calls to slow external systems during page rendering, with no timeout.
- Custom SQL that filters on unindexed columns.
- Rebuilding expensive data on every request instead of caching the result.
- Logging at DEBUG level in production, flooding disk and slowing every request.
Prevention beats diagnosis
Each of these is easy to introduce and easy to miss in code review until you know the pattern. The most effective performance work is cultural: a team that recognizes a query-in-a-loop or a disabled cache during review never ships it. Catching anti-patterns before they reach production is cheaper than every profiling session you would otherwise run.