LWC pages slow down for common reasons. The diagnostic and fix patterns:
Diagnose first:
- Lightning Performance Tools — Salesforce's own profiler. Run it; identify slow components.
- Browser DevTools Performance tab — record a page load; see which components rendered, network requests, etc.
- `performance.measure` in component code for custom timing.
Common fixes:
1. Lazy load. Components that aren't immediately visible (in collapsed accordions, hidden tabs) shouldn't load until needed.
javascript @track showHeavyComponent = false; handleClick() { this.showHeavyComponent = true; }
html <template if:true={showHeavyComponent}> <c-heavy-component></c-heavy-component> </template>
2. Cache `@wire` results. @AuraEnabled(cacheable=true) caches Apex results client-side. The same wire call across components shares cache.
3. Reduce wire reactivity. Don't use reactive variables ($prop) when the dependency rarely changes — initialise once, query manually if needed.
4. Defer heavy computation with `setTimeout(..., 0)` to yield to the browser:
javascript connectedCallback() { setTimeout(() => this.processData(), 0); }
5. Virtualize long lists. Use lightning-datatable (which virtualizes) instead of rendering 1000 rows manually.
6. Bulkify Apex calls. Don't call Apex per record; call once with all IDs. The same rule from Apex applies.
7. Reduce DOM size. Each rendered component costs memory. Avoid rendering 500 cards; paginate.
8. Avoid expensive synchronous work in `renderedCallback`. It runs every render; tight loops cause UI freezes.
9. Web Workers for heavy computation. For genuinely CPU-heavy client-side logic, move to a Web Worker.
10. Image optimisation. Compressed images, lazy loading via loading="lazy" attribute.
11. Avoid repeated SOQL. A list view that hits Apex per row is the most common slow page.
12. Use Lightning Data Service over Apex when possible — LDS shares cache across components.
LWS (Lightning Web Security) considerations — modern security model has slight perf overhead vs Aura's Lightning Locker; profile before assuming this is your bottleneck.
The single biggest win: stop unnecessary Apex calls. Most slow LWC pages are network-bound, not render-bound.
