Performance tuning starts with measurement, not assumptions.
Step 1: Measure.
- Lightning Performance Analysis in Salesforce.
- Browser DevTools for client-side render time.
- Debug logs with FINEST level for transaction analysis.
- Event Monitoring for slow query and slow Apex.
- User-reported pain points — qualitative.
Identify what's actually slow. Don't optimise based on hunches.
Step 2: Diagnose.
For each slow path:
- SOQL queries — non-selective, missing indexes, too many.
- DML — large bulk inserts, validation rules firing on every record.
- Triggers and flows — unbulkified, recursion.
- Lightning page composition — too many components, heavy LWCs.
- Network — slow callouts, unfiled latency.
- Sharing recalc — pending sharing operations.
Step 3: Prioritise.
- High user impact + high frequency — fix first.
- Quick wins — significant improvement with low effort.
- Long tail — many small inefficiencies; address as opportunity.
Step 4: Optimise.
For each hotspot:
SOQL:
- Index hits via WHERE on indexed fields.
- Custom Indexes via Salesforce Support.
- Selective queries (avoid full table scans).
- Skinny Tables for hot reads.
Triggers / Flow:
- Bulkify.
- Move sync work to async (Queueable, Future, Batch).
- Before-save flows for same-record updates.
- Reduce element count in Flow.
Lightning Pages:
- Lazy-load heavy components.
- Reduce component count.
- Cache
@wiredata. - Optimise images / static assets.
Apex code:
- Cache repeated queries.
- Use Maps / Sets, not List.contains.
- Aggregate SOQL where appropriate.
Step 5: Verify.
- Re-measure post-fix.
- Confirm improvement.
- Ensure no regressions.
Step 6: Monitor.
- Set up ongoing performance monitoring.
- Alert on regression.
- Trend over time.
Common pitfalls:
- Optimising without measuring — wasted effort.
- Optimising the wrong thing — visible but not the bottleneck.
- Local optimisation, global regression — fix one part, break another.
- No regression test — performance regresses silently.
Architect role: lead performance discipline. Establish standards (e.g., "page render < 2s"); enforce via automation (perf test in CI).
The senior insight: performance is a feature, not an afterthought. Build performance considerations into Discovery, design, code review.
