Performance: Each blocks ({#each})
MEDIUM IMPACT
This affects how many DOM nodes are created and updated during rendering, impacting page load and interaction speed.
<script> import { onMount } from 'svelte'; let items = []; let visibleCount = 20; onMount(() => { items = Array(1000).fill(0).map((_, i) => i); }); </script> <ul> {#each items.slice(0, visibleCount) as item} <li>{item}</li> {/each} </ul>
<script> let items = Array(1000).fill(0).map((_, i) => i); </script> <ul> {#each items as item} <li>{item}</li> {/each} </ul>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Render all items at once | 1000 nodes created | 1000 reflows | High paint cost | [X] Bad |
| Render limited items with slice | 20 nodes created | 20 reflows | Low paint cost | [OK] Good |