Skip to content

Commit 9a4fd5c

Browse files
keyed/svelte: optimize hot loop by eliminating extra whitespace nodes
Svelte does not currently [1] remove purely whitespace text nodes like most other frameworks do, which causes noticeable performance impact when benchmarking creating thousands of rows. This commit manually fixes that so that the generated HTML is closer to the competing implementations, using a workaround mentioned in [1]. On my system, all the benchmarks involving creation of rows run ~5% faster with this change and the overall geometric mean improves from around 1.28 to 1.25. [1]: sveltejs/svelte#6540
1 parent edaba88 commit 9a4fd5c

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

frameworks/keyed/svelte/src/Main.svelte

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@
3131
</div>
3232
<table class="table table-hover table-striped test-data">
3333
<tbody>
34-
{#each data as row, num (row.id)}
35-
<tr class={selected === row.id ? 'danger' : ''}>
36-
<td class="col-md-1">{row.id}</td>
37-
<td class="col-md-4">
38-
<a on:click={() => select(row.id)}>{row.label}</a>
39-
</td>
40-
<td class="col-md-1"><a on:click={() => remove(row.id)}><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td>
41-
<td class="col-md-6"></td>
42-
</tr>
34+
{#each data as row (row.id)}
35+
<tr class={selected === row.id ? 'danger' : ''}
36+
><td class="col-md-1">{row.id}</td><td class="col-md-4"
37+
><a on:click={() => select(row.id)}>{row.label}</a></td
38+
><td class="col-md-1"
39+
><a on:click={() => remove(row.id)}
40+
><span class="glyphicon glyphicon-remove" aria-hidden="true" /></a
41+
></td
42+
><td class="col-md-6" /></tr
43+
>
4344
{/each}
4445
</tbody>
4546
</table>

0 commit comments

Comments
 (0)