Performance: Middleware patterns with hooks
MEDIUM IMPACT
This affects the responsiveness and load time by controlling how code runs before and after component rendering.
import { onMount } from 'svelte'; onMount(async () => { await heavyAsyncTask(); });
import { onMount } from 'svelte'; onMount(() => { heavySyncTask(); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy synchronous tasks in onMount | Minimal | 0 but blocks JS thread | High due to blocking | [X] Bad |
| Async tasks in onMount | Minimal | 0 | Low | [OK] Good |
| Multiple separate beforeUpdate hooks updating state | Multiple | 2+ | High | [X] Bad |
| Single beforeUpdate hook batching state updates | Multiple | 1 | Medium | [OK] Good |