Performance: Optional parameters
LOW IMPACT
Optional parameters affect how components receive and handle data, impacting initial rendering and reactivity updates.
<script> export let title = "Default Title"; export let subtitle = null; </script> <h1>{title}</h1> {#if subtitle} <h2>{subtitle}</h2> {/if}
<script> export let title; export let subtitle; </script> <h1>{title}</h1> {#if subtitle} <h2>{subtitle}</h2> {/if}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No default for optional params | Extra reactive checks | Multiple reflows if params change | Higher paint cost due to re-renders | [X] Bad |
| Default values for optional params | Minimal reactive triggers | Single reflow on change | Lower paint cost with stable updates | [OK] Good |