Skip to content

perf(hooks): avoid redundant allocations and writes - #5115

Merged
JoviDeCroock merged 1 commit into
v10.xfrom
JoviDeCroock/improve-preact-performance
Jun 14, 2026
Merged

perf(hooks): avoid redundant allocations and writes#5115
JoviDeCroock merged 1 commit into
v10.xfrom
JoviDeCroock/improve-preact-performance

Conversation

@JoviDeCroock

Copy link
Copy Markdown
Member
  • updateHookState: drop the _list.filter() allocation and merge the every/some passes into a single traversal
  • options.diffed: only clear _pendingArgs when set, avoiding a write per hook per diff and shape pollution of non-effect hook states

hooks bundle: -11 B gzip / -9 B brotli.

@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown

📊 Tachometer Benchmark Results

Summary

duration

  • create10k: unsure 🔍 -1% - +0% (-10.75ms - +0.89ms)
    preact-local vs preact-main
  • filter-list: unsure 🔍 -0% - +1% (-0.03ms - +0.11ms)
    preact-local vs preact-main
  • hydrate1k: unsure 🔍 -2% - +1% (-1.29ms - +0.77ms)
    preact-local vs preact-main
  • many-updates: unsure 🔍 -0% - +1% (-0.05ms - +0.09ms)
    preact-local vs preact-main
  • replace1k: unsure 🔍 -2% - +2% (-1.17ms - +1.08ms)
    preact-local vs preact-main
  • text-update: slower ❌ 1% - 10% (0.03ms - 0.18ms)
    preact-local vs preact-main
  • todo: unsure 🔍 -3% - +1% (-1.00ms - +0.20ms)
    preact-local vs preact-main
  • update10th1k: unsure 🔍 -4% - +5% (-1.35ms - +1.59ms)
    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 🔍 -3% - +1% (-0.17ms - +0.03ms)
    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.00ms)
    preact-local vs preact-main
  • text-update: unsure 🔍 -5% - +1% (-0.06ms - +0.01ms)
    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.01ms)
    preact-local vs preact-main

Results

create10k

duration

VersionAvg timevs preact-localvs preact-main
preact-local828.12ms - 834.09ms-unsure 🔍
-1% - +0%
-10.75ms - +0.89ms
preact-main831.04ms - 841.03msunsure 🔍
-0% - +1%
-0.89ms - +10.75ms
-

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.52ms - 16.65ms-unsure 🔍
-0% - +1%
-0.03ms - +0.11ms
preact-main16.53ms - 16.57msunsure 🔍
-1% - +0%
-0.11ms - +0.03ms
-

usedJSHeapSize

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

duration

VersionAvg timevs preact-localvs preact-main
preact-local58.20ms - 59.55ms-unsure 🔍
-2% - +1%
-1.29ms - +0.77ms
preact-main58.35ms - 59.92msunsure 🔍
-1% - +2%
-0.77ms - +1.29ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local5.02ms - 5.03ms-unsure 🔍
-3% - +1%
-0.17ms - +0.03ms
preact-main5.00ms - 5.19msunsure 🔍
-1% - +3%
-0.03ms - +0.17ms
-
many-updates

duration

VersionAvg timevs preact-localvs preact-main
preact-local16.52ms - 16.57ms-unsure 🔍
-0% - +1%
-0.05ms - +0.09ms
preact-main16.46ms - 16.58msunsure 🔍
-1% - +0%
-0.09ms - +0.05ms
-

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 #5565
  • Commit: a762c6b

duration

VersionAvg timevs preact-localvs preact-main
preact-local59.23ms - 60.85ms-unsure 🔍
-2% - +2%
-1.17ms - +1.08ms
preact-main59.30ms - 60.87msunsure 🔍
-2% - +2%
-1.08ms - +1.17ms
-

usedJSHeapSize

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

run-warmup-0

VersionAvg timevs preact-localvs preact-main
preact-local27.51ms - 28.23ms-unsure 🔍
-1% - +3%
-0.30ms - +0.70ms
preact-main27.32ms - 28.02msunsure 🔍
-3% - +1%
-0.70ms - +0.30ms
-

run-warmup-1

VersionAvg timevs preact-localvs preact-main
preact-local32.59ms - 33.45ms-unsure 🔍
-1% - +2%
-0.38ms - +0.77ms
preact-main32.44ms - 33.20msunsure 🔍
-2% - +1%
-0.77ms - +0.38ms
-

run-warmup-2

VersionAvg timevs preact-localvs preact-main
preact-local32.44ms - 33.52ms-unsure 🔍
-2% - +2%
-0.69ms - +0.76ms
preact-main32.46ms - 33.44msunsure 🔍
-2% - +2%
-0.76ms - +0.69ms
-

run-warmup-3

VersionAvg timevs preact-localvs preact-main
preact-local27.20ms - 27.69ms-unsure 🔍
-1% - +2%
-0.30ms - +0.42ms
preact-main27.12ms - 27.65msunsure 🔍
-2% - +1%
-0.42ms - +0.30ms
-

run-warmup-4

VersionAvg timevs preact-localvs preact-main
preact-local22.99ms - 23.90ms-unsure 🔍
-3% - +3%
-0.59ms - +0.70ms
preact-main22.93ms - 23.85msunsure 🔍
-3% - +3%
-0.70ms - +0.59ms
-

run-final

VersionAvg timevs preact-localvs preact-main
preact-local22.23ms - 22.78ms-unsure 🔍
-1% - +3%
-0.11ms - +0.57ms
preact-main22.08ms - 22.48msunsure 🔍
-3% - +0%
-0.57ms - +0.11ms
-
text-update
  • Browser: chrome-headless
  • Sample size: 220
  • Built by: CI #5565
  • Commit: a762c6b

duration

VersionAvg timevs preact-localvs preact-main
preact-local2.00ms - 2.12ms-slower ❌
1% - 10%
0.03ms - 0.18ms
preact-main1.90ms - 2.01msfaster ✔
1% - 9%
0.03ms - 0.18ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local1.01ms - 1.06ms-unsure 🔍
-5% - +1%
-0.06ms - +0.01ms
preact-main1.03ms - 1.09msunsure 🔍
-1% - +6%
-0.01ms - +0.06ms
-
todo

duration

VersionAvg timevs preact-localvs preact-main
preact-local34.22ms - 34.81ms-unsure 🔍
-3% - +1%
-1.00ms - +0.20ms
preact-main34.39ms - 35.44msunsure 🔍
-1% - +3%
-0.20ms - +1.00ms
-

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

duration

VersionAvg timevs preact-localvs preact-main
preact-local32.87ms - 35.00ms-unsure 🔍
-4% - +5%
-1.35ms - +1.59ms
preact-main32.80ms - 34.83msunsure 🔍
-5% - +4%
-1.59ms - +1.35ms
-

usedJSHeapSize

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

tachometer-reporter-action v2 for CI

@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown

Size Change: -49 B (-0.06%)

Total Size: 79.2 kB

📦 View Changed
Filename Size Change
hooks/dist/hooks.js 1.51 kB -12 B (-0.79%)
hooks/dist/hooks.mjs 1.54 kB -12 B (-0.77%)
hooks/dist/hooks.module.js 1.54 kB -12 B (-0.77%)
hooks/dist/hooks.umd.js 1.58 kB -13 B (-0.82%)
ℹ️ 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
dist/preact.js 4.79 kB
dist/preact.min.js 4.81 kB
dist/preact.min.module.js 4.82 kB
dist/preact.min.umd.js 4.83 kB
dist/preact.mjs 4.82 kB
dist/preact.module.js 4.82 kB
dist/preact.umd.js 4.84 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 force-pushed the JoviDeCroock/improve-preact-performance branch 2 times, most recently from a965809 to c5ac055 Compare June 12, 2026 17:36
@JoviDeCroock
JoviDeCroock force-pushed the JoviDeCroock/improve-preact-performance branch from c5ac055 to a762c6b Compare June 12, 2026 17:37

@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 6aced21 into v10.x Jun 14, 2026
12 checks passed
@JoviDeCroock
JoviDeCroock deleted the JoviDeCroock/improve-preact-performance branch June 14, 2026 17:14
@JoviDeCroock JoviDeCroock mentioned this pull request Jun 25, 2026
JoviDeCroock added a commit that referenced this pull request Jun 25, 2026
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