Skip to content

Commit b1b231e

Browse files
committed
Stop v-if and v-for holding on to every list they ever rendered
Both take their element out of the document and keep it as the thing they clone from. The cleanup for that element -- the effect scope runDirective registered on it -- is keyed by that element, and destroy() walks live children only. Once detached nothing ever reached it, so the scope was never stopped and it held the template, every rendered block and every node inside them. Fifty mount-and-destroy cycles per size, heap forced between samples, kilobytes retained per cycle: 50 rows 393.6 -> 11.1 100 rows 749.7 -> 6.5 200 rows 1498.4 -> 13.0 The old figure doubles with the list because it was proportional to what had been rendered. The new one does not grow, and what is left is noise. It cost time as well as memory: the v-if toggle benchmark went from 5683 ms to 3079 ms once the garbage stopped accumulating. The project's own memory suite could not finish at all before this -- it exhausted a 3.8 GB heap and took the rest of the run down with it -- and now completes all thirteen cases. The hypothesis was already written down in benchmarks/memory/index.mjs with an A/B pair built to measure it. What was missing was routing destroy() to the detached templates, which it now does by recording them against the parent they left. Found by running the benchmark suite rather than by reading the code, and the suite crashing was the tell. Worth recording how nearly the regression test was useless: it passed 5/5, and it also passed against the unfixed code, because it collected nodes AFTER the walk -- by which point the template is already detached and therefore not in the list. Capturing before the walk is the entire test. It now fails 2 without the fix. Also here: both READMEs re-measured against the other six frameworks. Create improved in absolute terms, 97.70 to 80.81 ms, while the position moved from third of seven to fourth, because the others measured differently in the same run. Preact, Solid and Voodoo now finish within 0.4 ms of each other on a thousand-row create, which is a three-way tie no ranking column can express, and both tables now say that instead of claiming a place. The teardown chart is generated from the measurement now rather than hand-edited, the way the framework comparison already was. measure-teardown.mjs builds both versions, measures them and puts the source back.
1 parent 7bfb460 commit b1b231e

132 files changed

Lines changed: 2693 additions & 1269 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,54 @@ adopts [Semantic Versioning](https://semver.org/).
77

88
## [Unreleased]
99

10+
## [0.12.5] - 2026-09-04
11+
12+
### Fixed
13+
14+
- **`v-if` and `v-for` leaked everything they had ever rendered.** Both take
15+
their element out of the document and keep it as the thing they clone from.
16+
The cleanup for that element — the effect scope `runDirective` registered on
17+
it — is keyed by that element, and `destroy()` walks live children only. Once
18+
detached, nothing ever reached it: the scope was never stopped, and it held
19+
the template, every rendered block and every node inside them.
20+
21+
Fifty mount-and-destroy cycles per size, heap forced between samples, retained
22+
per cycle:
23+
24+
| rows | before | after |
25+
| ---: | ---: | ---: |
26+
| 50 | 393.6 KB | 11.1 KB |
27+
| 100 | 749.7 KB | 6.5 KB |
28+
| 200 | 1498.4 KB | 13.0 KB |
29+
30+
The old figure doubles with the list because it was proportional to what had
31+
been rendered; the new one does not grow, and what remains is noise.
32+
33+
It cost time as well as memory: the `v-if` toggle benchmark went from 5,683 ms
34+
to 3,079 ms once the garbage stopped accumulating. The project's own memory
35+
suite could not finish before this — it exhausted a 3.8 GB heap and took the
36+
rest of the run down with it — and now completes all thirteen cases.
37+
38+
The hypothesis was already written down in `benchmarks/memory/index.mjs`, with
39+
an A/B pair built to measure it. What was missing was routing `destroy()` to
40+
the detached templates, which it now does by recording them against the parent
41+
they left.
42+
43+
### Changed
44+
45+
- **The comparison numbers in both READMEs were re-measured**, and the honest
46+
reading changed with them. Create improved in absolute terms, 97.70 ms to
47+
80.81 ms, while the position moved from third of seven to fourth, because the
48+
other frameworks measured differently in the same run. Preact, Solid and
49+
Voodoo now finish within 0.4 ms of each other on a thousand-row create, which
50+
is a three-way tie a ranking column cannot express. Both tables say so.
51+
52+
- **The teardown chart is generated from the measurement** rather than hand-
53+
edited, the way the framework comparison already was.
54+
`node --expose-gc scripts/measure-teardown.mjs` builds both versions, measures
55+
them, restores the source, and writes the JSON that
56+
`scripts/chart-teardown.mjs` draws.
57+
1058
## [0.12.4] - 2026-09-04
1159

1260
### Fixed

‎README.md‎

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ compiler and no JSX transform.
3737
<!doctype html>
3838
<html>
3939
<head>
40-
<script src="https://cdn.jsdelivr.net/npm/voodoojs@0.12.3/dist/voodoo.full.min.js" defer></script>
40+
<script src="https://cdn.jsdelivr.net/npm/voodoojs@0.12.4/dist/voodoo.full.min.js" defer></script>
4141
</head>
4242
<body>
4343

@@ -281,11 +281,11 @@ Every row below is part of the shipped runtime.
281281
**A script tag, and nothing to install**
282282

283283
```html
284-
<script src="https://cdn.jsdelivr.net/npm/voodoojs@0.12.3/dist/voodoo.full.min.js" defer></script>
284+
<script src="https://cdn.jsdelivr.net/npm/voodoojs@0.12.4/dist/voodoo.full.min.js" defer></script>
285285
```
286286

287287
That is the whole installation. The library starts itself once the page is ready.
288-
[unpkg](https://unpkg.com/voodoojs@0.12.3/dist/voodoo.full.min.js) serves the same file if you prefer it.
288+
[unpkg](https://unpkg.com/voodoojs@0.12.4/dist/voodoo.full.min.js) serves the same file if you prefer it.
289289

290290
The tag above names an exact version, so what you load never changes under you and the page tells
291291
you which build it is. Use the `0.11` line instead if you would rather patch releases arrived on
@@ -313,7 +313,7 @@ import { debounce } from 'voodoojs/utils'
313313
For pages that must not reach a third-party host, or an air-gapped network:
314314

315315
```bash
316-
curl -O https://cdn.jsdelivr.net/npm/voodoojs@0.12.3/dist/voodoo.full.min.js
316+
curl -O https://cdn.jsdelivr.net/npm/voodoojs@0.12.4/dist/voodoo.full.min.js
317317
# or build from source
318318
git clone https://github.com/kwy404/Voodoo.js.git
319319
cd Voodoo.js && npm install && npm run build # bundles land in packages/voodoojs/dist/
@@ -553,7 +553,7 @@ watch `count` change in the panel while the button flashes on every write.
553553
<html lang="en">
554554
<head>
555555
<meta charset="utf-8">
556-
<script src="https://cdn.jsdelivr.net/npm/voodoojs@0.12.3/dist/voodoo.full.min.js" defer></script>
556+
<script src="https://cdn.jsdelivr.net/npm/voodoojs@0.12.4/dist/voodoo.full.min.js" defer></script>
557557
</head>
558558
<body>
559559
<div v-data="{ count: 0, items: ['a', 'b'] }">
@@ -632,15 +632,25 @@ environment and how to reproduce every measurement.
632632
Vanilla JavaScript is the ceiling here, and Voodoo charges a real cost for the productivity it
633633
buys. The point of these numbers is to show how large that cost is, not to pretend it is zero.
634634

635-
**Tearing down a keyed list.** Profiling found that `destroy()` was reading `node.childNodes`, a
636-
live collection the DOM rebuilds on every access and invalidates on every mutation. Walking siblings
637-
instead cut the cost of clearing a large list by about a third:
635+
**Tearing down a keyed list.** `v-if` and `v-for` take their element out of the document and keep it
636+
as the thing they clone from. The cleanup for that element — the effect scope holding the template,
637+
every rendered block and every node inside them — was keyed by that element, and `destroy()` walks
638+
live children only. Once detached, nothing ever reached it. The scope was never stopped and it held
639+
on to everything the list had ever rendered.
638640

639641
![v-for teardown: before and after](docs/media/vfor-teardown.svg)
640642

641-
Measured on Node 24 with jsdom, medians of repeated runs, on one machine. Treat it as the shape of
642-
the change, not as an absolute number: your browser is not jsdom. The full method is in
643-
[`benchmarks/README.md`](benchmarks/README.md).
643+
The old figure grew with the list, because it was proportional to what had been rendered: 394 KB
644+
retained per mount at 50 rows, 750 KB at 100, 1.5 MB at 200. The new one does not grow, and what is
645+
left is noise rather than retention. The project's own memory benchmark could not finish before this
646+
— it exhausted a 3.8 GB heap and took the rest of the suite down with it — and the `v-if` toggle
647+
case dropped from 5,683 ms to 3,079 ms once the garbage stopped accumulating, so the leak was
648+
costing time as well as memory.
649+
650+
Measured on Node 24 with jsdom, fifty mount-and-destroy cycles per size with the heap forced between
651+
samples, on one machine. Treat it as the shape of the change rather than an absolute number: your
652+
browser is not jsdom. Reproduce with `node --expose-gc scripts/measure-teardown.mjs`, which builds
653+
both versions, measures them and puts the source back.
644654

645655
One honest caveat from the same run: list *creation* at this size is dominated by the DOM itself.
646656
Inserting 4,000 nodes with no framework at all took longer in jsdom than Voodoo's whole render, so
@@ -658,24 +668,32 @@ Median of 30 samples, in milliseconds, lower is better. Voodoo.js in bold:
658668

659669
| | create 1k | update every 10th | clear 1k | minified |
660670
| --- | ---: | ---: | ---: | ---: |
661-
| vanilla JS | 48.74 | 7.52 | 21.06 | 0.6 KB |
662-
| Preact 10.29.8 | 91.62 | 2.59 | 29.48 | 10.7 KB |
663-
| **Voodoo.js** | **97.70** | **5.42** | **30.44** | **416.9 KB** |
664-
| React 19.2.8 | 100.23 | 4.63 | 33.59 | 189.3 KB |
665-
| Vue 3.5.42 | 110.56 | 19.21 | 31.65 | 62.5 KB |
666-
| Solid 1.9.15 | 111.63 | 0.91 | 19.99 | 16.7 KB |
667-
| Alpine 3.17.1 | 179.47 | 104.51 | 31.39 | 55.2 KB |
668-
669-
Read honestly. On create Voodoo is **third of seven** — behind hand-written vanilla and Preact,
670-
ahead of React, Vue and Solid. On clear it is **fourth**. Both were substantially worse before the
671-
optimisation pass described below, and neither is a victory lap: vanilla still creates a list twice
672-
as fast as we do.
673-
674-
On update Voodoo sits just ahead of hand-written vanilla and roughly **19x ahead of Alpine**, which
675-
is the fair comparison, since Alpine is also HTML-first and also interprets expressions at runtime
676-
rather than compiling them. Treat that number as a range rather than a ranking: the update scenario
677-
is the noisiest of the three, and a paired A/B against the pre-optimisation build measured **no
678-
change at all** on update. We are not claiming to have beaten vanilla on the strength of one sample.
671+
| vanilla JS | 56.71 | 7.51 | 32.39 | 0.6 KB |
672+
| Preact 10.29.8 | 80.40 | 2.54 | 31.68 | 10.7 KB |
673+
| Solid 1.9.15 | 80.73 | 0.82 | 23.83 | 16.7 KB |
674+
| **Voodoo.js** | **80.81** | **7.91** | **34.46** | **429.2 KB** |
675+
| React 19.2.8 | 84.97 | 4.68 | 37.15 | 189.3 KB |
676+
| Vue 3.5.42 | 89.66 | 11.90 | 34.98 | 62.5 KB |
677+
| Alpine 3.17.1 | 166.03 | 104.98 | 37.67 | 55.2 KB |
678+
679+
Read honestly, and read the spread before the order. On create, Preact, Solid and Voodoo finish
680+
within **0.4 ms of each other** across a 1,000-row list — that is a three-way tie the ranking column
681+
cannot express, and calling it fourth place would be as misleading as calling it second. Vanilla
682+
still builds the list a third faster than any framework here.
683+
684+
On clear the same is true of the middle of the field: vanilla, Preact, Voodoo and Vue land inside
685+
3 ms. Solid wins it outright.
686+
687+
On update Voodoo is level with hand-written vanilla — 7.91 against 7.51, well inside the run-to-run
688+
noise — and roughly **13x ahead of Alpine**, which is the comparison that actually means something,
689+
since Alpine is also HTML-first and also interprets expressions at runtime instead of compiling
690+
them. Solid and Preact are far ahead of both, and they get there with a compiler.
691+
692+
An earlier version of this table reported create at 97.70 ms and called it third of seven. The
693+
absolute number improved to 80.81 while the position moved to fourth, because the other frameworks
694+
measured differently in the same run. That is what a coefficient of variation of 31% on create and
695+
54% on update looks like from the outside, and it is the reason these are presented as a field
696+
rather than a leaderboard.
679697

680698
Solid wins update by a wide margin because a compiler generates its update path. Voodoo has no build
681699
step, and that is the trade it makes.

‎README.pt-BR.md‎

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ compilador e não tem transform de JSX.
3737
<!doctype html>
3838
<html>
3939
<head>
40-
<script src="https://cdn.jsdelivr.net/npm/voodoojs@0.12.3/dist/voodoo.full.min.js" defer></script>
40+
<script src="https://cdn.jsdelivr.net/npm/voodoojs@0.12.4/dist/voodoo.full.min.js" defer></script>
4141
</head>
4242
<body>
4343

@@ -287,11 +287,11 @@ Cada linha abaixo faz parte do runtime publicado.
287287
**Uma tag script, e nada para instalar**
288288

289289
```html
290-
<script src="https://cdn.jsdelivr.net/npm/voodoojs@0.12.3/dist/voodoo.full.min.js" defer></script>
290+
<script src="https://cdn.jsdelivr.net/npm/voodoojs@0.12.4/dist/voodoo.full.min.js" defer></script>
291291
```
292292

293293
Essa é a instalação inteira. A biblioteca começa sozinha assim que a página fica pronta. O
294-
[unpkg](https://unpkg.com/voodoojs@0.12.3/dist/voodoo.full.min.js) serve o mesmo arquivo, se você preferir.
294+
[unpkg](https://unpkg.com/voodoojs@0.12.4/dist/voodoo.full.min.js) serve o mesmo arquivo, se você preferir.
295295

296296
A tag acima nomeia uma versão exata, então o que você carrega não muda sozinho e a página diz qual
297297
build é. Use a linha `0.11` se preferir que as correções de patch cheguem sem edição. É o build
@@ -319,7 +319,7 @@ import { debounce } from 'voodoojs/utils'
319319
Para páginas que não podem depender de um host de terceiros, ou uma rede isolada:
320320

321321
```bash
322-
curl -O https://cdn.jsdelivr.net/npm/voodoojs@0.12.3/dist/voodoo.full.min.js
322+
curl -O https://cdn.jsdelivr.net/npm/voodoojs@0.12.4/dist/voodoo.full.min.js
323323
# ou compile a partir do código
324324
git clone https://github.com/kwy404/Voodoo.js.git
325325
cd Voodoo.js && npm install && npm run build # os bundles saem em packages/voodoojs/dist/
@@ -565,7 +565,7 @@ Uma página completa. Salve, abra, clique algumas vezes no botão, aperte as tec
565565
<html lang="pt-BR">
566566
<head>
567567
<meta charset="utf-8">
568-
<script src="https://cdn.jsdelivr.net/npm/voodoojs@0.12.3/dist/voodoo.full.min.js" defer></script>
568+
<script src="https://cdn.jsdelivr.net/npm/voodoojs@0.12.4/dist/voodoo.full.min.js" defer></script>
569569
</head>
570570
<body>
571571
<div v-data="{ count: 0, items: ['a', 'b'] }">
@@ -644,15 +644,25 @@ reproduzir cada medição.
644644
O JavaScript puro é o teto aqui, e a Voodoo cobra um custo real pela produtividade que entrega. A
645645
função destes números é mostrar o tamanho desse custo, não fingir que ele é zero.
646646

647-
**Desmontar uma lista com chave.** O perfil mostrou que o `destroy()` lia `node.childNodes`, uma
648-
coleção viva que o DOM reconstrói a cada acesso e invalida a cada mudança na árvore. Trocar por
649-
travessia entre irmãos cortou cerca de um terço do custo de limpar uma lista grande:
647+
**Desmontar uma lista com chave.** O `v-if` e o `v-for` tiram o elemento do documento e passam a
648+
usá-lo como o modelo que clonam. A limpeza desse elemento — o escopo de efeito que segurava o
649+
modelo, cada bloco renderizado e cada nó dentro deles — estava indexada por ele, e o `destroy()` só
650+
percorre filhos vivos. Depois de destacado, nada mais o alcançava: o escopo nunca parava e segurava
651+
tudo que a lista já tinha renderizado.
650652

651653
![Desmontagem do v-for: antes e depois](docs/media/vfor-teardown.svg)
652654

653-
Medido no Node 24 com jsdom, medianas de execuções repetidas, em uma máquina só. Leia como a forma
654-
da mudança, e não como número absoluto: o seu navegador não é o jsdom. A metodologia completa está
655-
em [`benchmarks/README.md`](benchmarks/README.md).
655+
O número antigo crescia com a lista, porque era proporcional ao que tinha sido renderizado: 394 KB
656+
retidos por montagem com 50 linhas, 750 KB com 100, 1,5 MB com 200. O novo não cresce, e o que
657+
sobra é ruído, não retenção. O benchmark de memória do próprio projeto não conseguia terminar antes
658+
disso — estourava um heap de 3,8 GB e derrubava o resto do suite junto — e o caso de alternância do
659+
`v-if` caiu de 5.683 ms para 3.079 ms quando o lixo parou de se acumular, ou seja, o vazamento
660+
custava tempo além de memória.
661+
662+
Medido no Node 24 com jsdom, cinquenta ciclos de montar e destruir por tamanho, com coleta forçada
663+
entre as amostras, em uma máquina só. Leia como a forma da mudança, e não como número absoluto: o
664+
seu navegador não é o jsdom. Reproduza com `node --expose-gc scripts/measure-teardown.mjs`, que
665+
constrói as duas versões, mede e devolve o fonte ao estado original.
656666

657667
Uma ressalva honesta da mesma medição: a *criação* da lista nesse tamanho é dominada pelo próprio
658668
DOM. Inserir 4.000 nós sem framework nenhum levou mais tempo no jsdom do que a renderização inteira
@@ -670,25 +680,33 @@ Mediana de 30 amostras, em milissegundos, menor é melhor. Voodoo.js em negrito:
670680

671681
| | criar 1k | atualizar 1 em 10 | limpar 1k | minificado |
672682
| --- | ---: | ---: | ---: | ---: |
673-
| vanilla JS | 48,74 | 7,52 | 21,06 | 0,6 KB |
674-
| Preact 10.29.8 | 91,62 | 2,59 | 29,48 | 10,7 KB |
675-
| **Voodoo.js** | **97,70** | **5,42** | **30,44** | **416,9 KB** |
676-
| React 19.2.8 | 100,23 | 4,63 | 33,59 | 189,3 KB |
677-
| Vue 3.5.42 | 110,56 | 19,21 | 31,65 | 62,5 KB |
678-
| Solid 1.9.15 | 111,63 | 0,91 | 19,99 | 16,7 KB |
679-
| Alpine 3.17.1 | 179,47 | 104,51 | 31,39 | 55,2 KB |
680-
681-
Lendo com honestidade. Na criação a Voodoo é **terceira de sete**, atrás do vanilla escrito à mão e
682-
do Preact, à frente de React, Vue e Solid. Na limpeza é a **quarta**. Os dois resultados eram
683-
bem piores antes do trabalho de otimização descrito abaixo, e nenhum dos dois é volta olímpica: o
684-
vanilla ainda cria uma lista duas vezes mais rápido que a gente.
685-
686-
Na atualização a Voodoo fica um pouco à frente do vanilla escrito à mão e cerca de **19x à frente
687-
do Alpine**, que é a comparação justa: o Alpine também é HTML-first e também interpreta expressões
688-
em tempo de execução, em vez de compilá-las. Trate esse número como faixa, e não como classificação:
689-
a atualização é o cenário mais ruidoso dos três, e um teste pareado contra o build anterior à
690-
otimização mediu **nenhuma mudança** na atualização. Não estamos afirmando ter ganhado do vanilla
691-
com base numa amostra só.
683+
| vanilla JS | 56,71 | 7,51 | 32,39 | 0,6 KB |
684+
| Preact 10.29.8 | 80,40 | 2,54 | 31,68 | 10,7 KB |
685+
| Solid 1.9.15 | 80,73 | 0,82 | 23,83 | 16,7 KB |
686+
| **Voodoo.js** | **80,81** | **7,91** | **34,46** | **429,2 KB** |
687+
| React 19.2.8 | 84,97 | 4,68 | 37,15 | 189,3 KB |
688+
| Vue 3.5.42 | 89,66 | 11,90 | 34,98 | 62,5 KB |
689+
| Alpine 3.17.1 | 166,03 | 104,98 | 37,67 | 55,2 KB |
690+
691+
Lendo com honestidade, e lendo a diferença antes da ordem. Na criação, Preact, Solid e Voodoo
692+
terminam a **0,4 ms uma da outra** numa lista de mil linhas — é um empate triplo que a coluna de
693+
classificação não consegue expressar, e chamar isso de quarto lugar enganaria tanto quanto chamar
694+
de segundo. O vanilla ainda monta a lista um terço mais rápido que qualquer framework aqui.
695+
696+
Na limpeza vale o mesmo para o meio do pelotão: vanilla, Preact, Voodoo e Vue ficam dentro de 3 ms.
697+
O Solid ganha essa com folga.
698+
699+
Na atualização a Voodoo empata com o vanilla escrito à mão — 7,91 contra 7,51, bem dentro do ruído
700+
entre execuções — e fica cerca de **13x à frente do Alpine**, que é a comparação que realmente
701+
significa alguma coisa, já que o Alpine também é HTML-first e também interpreta expressões em tempo
702+
de execução em vez de compilá-las. Solid e Preact estão muito à frente dos dois, e chegam lá com um
703+
compilador.
704+
705+
Uma versão anterior desta tabela trazia a criação em 97,70 ms e chamava de terceira de sete. O
706+
número absoluto melhorou para 80,81 enquanto a posição caiu para quarta, porque os outros
707+
frameworks mediram diferente na mesma execução. É assim que um coeficiente de variação de 31% na
708+
criação e 54% na atualização se parece de fora, e é por isso que estes números são apresentados
709+
como um pelotão e não como um pódio.
692710

693711
O Solid ganha a atualização com folga larga porque um compilador gera o caminho de atualização
694712
dele. A Voodoo não tem passo de build, e essa é a troca que ela faz.

‎SECURITY.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ You handle:
499499
- Serving over HTTPS. Subresource Integrity on the CDN tag is recommended:
500500

501501
```html
502-
<script src="https://cdn.jsdelivr.net/npm/voodoojs@0.12.3/dist/voodoo.full.min.js"
502+
<script src="https://cdn.jsdelivr.net/npm/voodoojs@0.12.4/dist/voodoo.full.min.js"
503503
integrity="sha384-..."
504504
crossorigin="anonymous"
505505
defer></script>
@@ -533,7 +533,7 @@ the published `dist/`. `packages/voodoojs/package.json` restricts the published
533533
To verify a published bundle:
534534

535535
```bash
536-
npm pack voodoojs@0.12.3
536+
npm pack voodoojs@0.12.4
537537
grep -c "eval(\|new Function" package/dist/voodoo.min.js # expect 0
538538
```
539539

0 commit comments

Comments
 (0)