Skip to content

Fix memory leak hotspots - #5116

Merged
JoviDeCroock merged 1 commit into
v10.xfrom
JoviDeCroock/fix-memory-leak-hotspots
Jun 15, 2026
Merged

Fix memory leak hotspots#5116
JoviDeCroock merged 1 commit into
v10.xfrom
JoviDeCroock/fix-memory-leak-hotspots

Conversation

@JoviDeCroock

@JoviDeCroock JoviDeCroock commented Jun 12, 2026

Copy link
Copy Markdown
Member

Local replace1k check: run-final 10.99ms vs 10.79ms main, overlapping CI.

@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown

📊 Tachometer Benchmark Results

Summary

duration

  • create10k: unsure 🔍 -1% - +0% (-5.06ms - +1.18ms)
    preact-local vs preact-main
  • filter-list: unsure 🔍 -1% - +0% (-0.15ms - +0.05ms)
    preact-local vs preact-main
  • hydrate1k: unsure 🔍 -2% - +1% (-1.19ms - +0.29ms)
    preact-local vs preact-main
  • many-updates: unsure 🔍 -0% - +0% (-0.04ms - +0.04ms)
    preact-local vs preact-main
  • replace1k: unsure 🔍 -1% - +1% (-0.78ms - +0.80ms)
    preact-local vs preact-main
  • text-update: unsure 🔍 -1% - +8% (-0.02ms - +0.15ms)
    preact-local vs preact-main
  • todo: unsure 🔍 -2% - +1% (-0.53ms - +0.36ms)
    preact-local vs preact-main
  • update10th1k: unsure 🔍 -7% - +1% (-1.76ms - +0.33ms)
    preact-local vs preact-main

usedJSHeapSize

  • create10k: unsure 🔍 +0% - +0% (+0.00ms - +0.00ms)
    preact-local vs preact-main
  • filter-list: unsure 🔍 -0% - +0% (-0.00ms - +0.00ms)
    preact-local vs preact-main
  • hydrate1k: unsure 🔍 -5% - +4% (-0.25ms - +0.19ms)
    preact-local vs preact-main
  • many-updates: unsure 🔍 -0% - +0% (-0.00ms - +0.00ms)
    preact-local vs preact-main
  • replace1k: unsure 🔍 -0% - +0% (-0.00ms - +0.01ms)
    preact-local vs preact-main
  • text-update: unsure 🔍 -5% - +2% (-0.06ms - +0.02ms)
    preact-local vs preact-main
  • todo: unsure 🔍 +0% - +0% (+0.00ms - +0.00ms)
    preact-local vs preact-main
  • update10th1k: unsure 🔍 -0% - +0% (-0.01ms - +0.00ms)
    preact-local vs preact-main

Results

create10k

duration

VersionAvg timevs preact-localvs preact-main
preact-local830.79ms - 835.13ms-unsure 🔍
-1% - +0%
-5.06ms - +1.18ms
preact-main832.65ms - 837.14msunsure 🔍
-0% - +1%
-1.18ms - +5.06ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local19.21ms - 19.21ms-unsure 🔍
+0% - +0%
+0.00ms - +0.00ms
preact-main19.21ms - 19.21msunsure 🔍
-0% - -0%
-0.00ms - -0.00ms
-
filter-list

duration

VersionAvg timevs preact-localvs preact-main
preact-local16.57ms - 16.65ms-unsure 🔍
-1% - +0%
-0.15ms - +0.05ms
preact-main16.57ms - 16.75msunsure 🔍
-0% - +1%
-0.05ms - +0.15ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local1.57ms - 1.57ms-unsure 🔍
-0% - +0%
-0.00ms - +0.00ms
preact-main1.57ms - 1.57msunsure 🔍
-0% - +0%
-0.00ms - +0.00ms
-
hydrate1k

duration

VersionAvg timevs preact-localvs preact-main
preact-local55.57ms - 56.58ms-unsure 🔍
-2% - +1%
-1.19ms - +0.29ms
preact-main55.98ms - 57.07msunsure 🔍
-1% - +2%
-0.29ms - +1.19ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local5.07ms - 5.34ms-unsure 🔍
-5% - +4%
-0.25ms - +0.19ms
preact-main5.06ms - 5.40msunsure 🔍
-4% - +5%
-0.19ms - +0.25ms
-
many-updates

duration

VersionAvg timevs preact-localvs preact-main
preact-local16.52ms - 16.57ms-unsure 🔍
-0% - +0%
-0.04ms - +0.04ms
preact-main16.52ms - 16.57msunsure 🔍
-0% - +0%
-0.04ms - +0.04ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local3.73ms - 3.73ms-unsure 🔍
-0% - +0%
-0.00ms - +0.00ms
preact-main3.73ms - 3.73msunsure 🔍
-0% - +0%
-0.00ms - +0.00ms
-
replace1k
  • Browser: chrome-headless
  • Sample size: 100
  • Built by: CI #5567
  • Commit: 5670ac8

duration

VersionAvg timevs preact-localvs preact-main
preact-local55.49ms - 56.65ms-unsure 🔍
-1% - +1%
-0.78ms - +0.80ms
preact-main55.52ms - 56.60msunsure 🔍
-1% - +1%
-0.80ms - +0.78ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local3.02ms - 3.02ms-unsure 🔍
-0% - +0%
-0.00ms - +0.01ms
preact-main3.01ms - 3.02msunsure 🔍
-0% - +0%
-0.01ms - +0.00ms
-

run-warmup-0

VersionAvg timevs preact-localvs preact-main
preact-local27.29ms - 27.92ms-unsure 🔍
-3% - +1%
-0.78ms - +0.19ms
preact-main27.53ms - 28.26msunsure 🔍
-1% - +3%
-0.19ms - +0.78ms
-

run-warmup-1

VersionAvg timevs preact-localvs preact-main
preact-local31.69ms - 32.69ms-unsure 🔍
-2% - +2%
-0.57ms - +0.79ms
preact-main31.63ms - 32.53msunsure 🔍
-2% - +2%
-0.79ms - +0.57ms
-

run-warmup-2

VersionAvg timevs preact-localvs preact-main
preact-local32.16ms - 33.40ms-unsure 🔍
-2% - +3%
-0.57ms - +1.09ms
preact-main31.97ms - 33.08msunsure 🔍
-3% - +2%
-1.09ms - +0.57ms
-

run-warmup-3

VersionAvg timevs preact-localvs preact-main
preact-local25.57ms - 25.98ms-unsure 🔍
-2% - +0%
-0.59ms - +0.11ms
preact-main25.73ms - 26.29msunsure 🔍
-0% - +2%
-0.11ms - +0.59ms
-

run-warmup-4

VersionAvg timevs preact-localvs preact-main
preact-local22.49ms - 23.54ms-unsure 🔍
-2% - +4%
-0.47ms - +1.01ms
preact-main22.22ms - 23.28msunsure 🔍
-4% - +2%
-1.01ms - +0.47ms
-

run-final

VersionAvg timevs preact-localvs preact-main
preact-local21.08ms - 21.46ms-unsure 🔍
-1% - +1%
-0.30ms - +0.20ms
preact-main21.16ms - 21.49msunsure 🔍
-1% - +1%
-0.20ms - +0.30ms
-
text-update
  • Browser: chrome-headless
  • Sample size: 230
  • Built by: CI #5567
  • Commit: 5670ac8

duration

VersionAvg timevs preact-localvs preact-main
preact-local2.00ms - 2.13ms-unsure 🔍
-1% - +8%
-0.02ms - +0.15ms
preact-main1.94ms - 2.05msunsure 🔍
-7% - +1%
-0.15ms - +0.02ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local1.03ms - 1.09ms-unsure 🔍
-5% - +2%
-0.06ms - +0.02ms
preact-main1.05ms - 1.11msunsure 🔍
-2% - +5%
-0.02ms - +0.06ms
-
todo

duration

VersionAvg timevs preact-localvs preact-main
preact-local34.57ms - 35.21ms-unsure 🔍
-2% - +1%
-0.53ms - +0.36ms
preact-main34.66ms - 35.28msunsure 🔍
-1% - +2%
-0.36ms - +0.53ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local1.26ms - 1.26ms-unsure 🔍
+0% - +0%
+0.00ms - +0.00ms
preact-main1.26ms - 1.26msunsure 🔍
-0% - -0%
-0.00ms - -0.00ms
-
update10th1k
  • Browser: chrome-headless
  • Sample size: 160
  • Built by: CI #5567
  • Commit: 5670ac8

duration

VersionAvg timevs preact-localvs preact-main
preact-local25.32ms - 26.68ms-unsure 🔍
-7% - +1%
-1.76ms - +0.33ms
preact-main25.92ms - 27.51msunsure 🔍
-1% - +7%
-0.33ms - +1.76ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local2.99ms - 2.99ms-unsure 🔍
-0% - +0%
-0.01ms - +0.00ms
preact-main2.99ms - 2.99msunsure 🔍
-0% - +0%
-0.00ms - +0.01ms
-

tachometer-reporter-action v2 for CI

@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown

Size Change: +60 B (+0.08%)

Total Size: 79.3 kB

📦 View Changed
Filename Size Change
dist/preact.js 4.8 kB +9 B (+0.19%)
dist/preact.min.js 4.82 kB +9 B (+0.19%)
dist/preact.min.module.js 4.83 kB +8 B (+0.17%)
dist/preact.min.umd.js 4.84 kB +9 B (+0.19%)
dist/preact.mjs 4.83 kB +9 B (+0.19%)
dist/preact.module.js 4.83 kB +9 B (+0.19%)
dist/preact.umd.js 4.85 kB +7 B (+0.14%)
ℹ️ View Unchanged
Filename Size
compat/dist/compat.js 4.19 kB
compat/dist/compat.mjs 4.11 kB
compat/dist/compat.module.js 4.11 kB
compat/dist/compat.umd.js 4.25 kB
debug/dist/debug.js 3.85 kB
debug/dist/debug.mjs 3.85 kB
debug/dist/debug.module.js 3.85 kB
debug/dist/debug.umd.js 3.93 kB
devtools/dist/devtools.js 259 B
devtools/dist/devtools.mjs 274 B
devtools/dist/devtools.module.js 274 B
devtools/dist/devtools.umd.js 345 B
hooks/dist/hooks.js 1.52 kB
hooks/dist/hooks.mjs 1.56 kB
hooks/dist/hooks.module.js 1.56 kB
hooks/dist/hooks.umd.js 1.59 kB
jsx-runtime/dist/jsxRuntime.js 1.01 kB
jsx-runtime/dist/jsxRuntime.mjs 985 B
jsx-runtime/dist/jsxRuntime.module.js 985 B
jsx-runtime/dist/jsxRuntime.umd.js 1.08 kB
test-utils/dist/testUtils.js 473 B
test-utils/dist/testUtils.mjs 477 B
test-utils/dist/testUtils.module.js 477 B
test-utils/dist/testUtils.umd.js 555 B

compressed-size-action

@JoviDeCroock

JoviDeCroock commented Jun 12, 2026

Copy link
Copy Markdown
Member Author

I feel like I've done this before but... time to analyze why replace is degrading this much... Probably hitting GC a lot more...

EDIT: yes removing the _unmount reset of _children did the trick https://github.com/preactjs/preact/compare/c40fd133c1cd7dc452ba1594a763c0776807a01f..5670ac8b8b9222783d2527ebbac88c021995b7b8

- render: clear the root Fragment's props.children after commit so replaced vnode generations are not retained

- unmount: clear component._globalContext with the other component references
@JoviDeCroock
JoviDeCroock force-pushed the JoviDeCroock/fix-memory-leak-hotspots branch from c40fd13 to 5670ac8 Compare June 13, 2026 04:45

@marvinhagemeister marvinhagemeister left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice find!

@JoviDeCroock
JoviDeCroock merged commit bd0302d into v10.x Jun 15, 2026
12 checks passed
@JoviDeCroock
JoviDeCroock deleted the JoviDeCroock/fix-memory-leak-hotspots branch June 15, 2026 06:18
@JoviDeCroock JoviDeCroock mentioned this pull request Jun 25, 2026
JoviDeCroock added a commit that referenced this pull request Jun 25, 2026
- render: clear the root Fragment's props.children after commit so replaced vnode generations are not retained

- unmount: clear component._globalContext with the other component references

(cherry picked from commit bd0302d)
JoviDeCroock added a commit that referenced this pull request Jun 26, 2026
* Fix hydrate error recovery with null excess DOM children (#5112)

(cherry picked from commit 82ed24e)

* perf(hooks): avoid redundant allocations and writes in SCU and diffed (#5115)

(cherry picked from commit 6aced21)

* Fix memory leak hotspots (#5116)

- render: clear the root Fragment's props.children after commit so replaced vnode generations are not retained

- unmount: clear component._globalContext with the other component references

(cherry picked from commit bd0302d)

* Flush subtree effects (#5055)

(cherry picked from commit d9e8984)

* Fix useId stability across async Suspense (#5108)

Assisted-By: devx/1b997072-d89c-4f6a-a18f-9525b3ef7a9e
(cherry picked from commit 67f0290)

* Fix error recovery for partially rendered subtrees (#5120)

When a component throws after `diffChildren()` has already started, its
`newVNode._children` may contain partially mounted children. The error recovery
path always replaced those children with `oldVNode._children`, which can be
`undefined` during initial mount.

That loses the partially rendered subtree, so children that queued updates are
not unmounted and keep their _parentDom. A later queued update can then call
`getDomSibling()` through an ancestor whose `_children` is undefined and crash.

Only restore old children when the new vnode has no children yet, and discard
commit/ref queue entries produced by the failed partial render so lifecycles from
the aborted subtree are not committed.

(cherry picked from commit 1a3b8b5)
@JoviDeCroock JoviDeCroock mentioned this pull request Jul 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants