Skip to content

Hoist _children into a local in constructNewChildrenArray - #5198

Merged
JoviDeCroock merged 2 commits into
mainfrom
JoviDeCroock/issue-2618-algo-learnings
Aug 7, 2026
Merged

Hoist _children into a local in constructNewChildrenArray#5198
JoviDeCroock merged 2 commits into
mainfrom
JoviDeCroock/issue-2618-algo-learnings

Conversation

@JoviDeCroock

@JoviDeCroock JoviDeCroock commented Aug 7, 2026

Copy link
Copy Markdown
Member

Every normalization branch in constructNewChildrenArray's loop wrote through newParentVNode._children[i], reloading the property on each branch. Bind it once and write through the local instead.

−5 B brotli (4582 → 4577), performance-neutral everywhere.

Fixed up by Claude opus

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

📊 Tachometer Benchmark Results

Summary

duration

  • create10k: unsure 🔍 -1% - +1% (-4.73ms - +5.45ms)
    preact-local vs preact-main
  • filter-list: unsure 🔍 -1% - +0% (-0.14ms - +0.04ms)
    preact-local vs preact-main
  • hydrate1k: unsure 🔍 -4% - +1% (-2.77ms - +0.55ms)
    preact-local vs preact-main
  • many-updates: unsure 🔍 -0% - +0% (-0.07ms - +0.02ms)
    preact-local vs preact-main
  • replace1k: unsure 🔍 -1% - +2% (-0.61ms - +1.26ms)
    preact-local vs preact-main
  • text-update: unsure 🔍 -6% - +3% (-0.11ms - +0.05ms)
    preact-local vs preact-main
  • todo: unsure 🔍 -1% - +2% (-0.26ms - +0.79ms)
    preact-local vs preact-main
  • update10th1k: unsure 🔍 -5% - +3% (-1.47ms - +1.08ms)
    preact-local vs preact-main

usedJSHeapSize

  • create10k: unsure 🔍 -0% - +0% (-0.03ms - +0.02ms)
    preact-local vs preact-main
  • filter-list: unsure 🔍 -0% - -0% (-0.01ms - -0.00ms)
    preact-local vs preact-main
  • hydrate1k: unsure 🔍 -1% - +2% (-0.04ms - +0.10ms)
    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 🔍 -2% - +6% (-0.02ms - +0.07ms)
    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-local811.59ms - 819.58ms-unsure 🔍
-1% - +1%
-4.73ms - +5.45ms
preact-main812.08ms - 818.38msunsure 🔍
-1% - +1%
-5.45ms - +4.73ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local19.21ms - 19.25ms-unsure 🔍
-0% - +0%
-0.03ms - +0.02ms
preact-main19.22ms - 19.26msunsure 🔍
-0% - +0%
-0.02ms - +0.03ms
-
filter-list

duration

VersionAvg timevs preact-localvs preact-main
preact-local16.56ms - 16.63ms-unsure 🔍
-1% - +0%
-0.14ms - +0.04ms
preact-main16.56ms - 16.73msunsure 🔍
-0% - +1%
-0.04ms - +0.14ms
-

usedJSHeapSize

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

duration

VersionAvg timevs preact-localvs preact-main
preact-local61.86ms - 64.61ms-unsure 🔍
-4% - +1%
-2.77ms - +0.55ms
preact-main63.42ms - 65.28msunsure 🔍
-1% - +4%
-0.55ms - +2.77ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local4.99ms - 5.13ms-unsure 🔍
-1% - +2%
-0.04ms - +0.10ms
preact-main5.02ms - 5.03msunsure 🔍
-2% - +1%
-0.10ms - +0.04ms
-
many-updates

duration

VersionAvg timevs preact-localvs preact-main
preact-local16.51ms - 16.58ms-unsure 🔍
-0% - +0%
-0.07ms - +0.02ms
preact-main16.55ms - 16.60msunsure 🔍
-0% - +0%
-0.02ms - +0.07ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local3.75ms - 3.75ms-unsure 🔍
-0% - -0%
-0.00ms - -0.00ms
preact-main3.76ms - 3.76msunsure 🔍
+0% - +0%
+0.00ms - +0.00ms
-
replace1k
  • Browser: chrome-headless
  • Sample size: 100
  • Built by: CI #5817
  • Commit: c0c3646

duration

VersionAvg timevs preact-localvs preact-main
preact-local55.96ms - 57.29ms-unsure 🔍
-1% - +2%
-0.61ms - +1.26ms
preact-main55.64ms - 56.95msunsure 🔍
-2% - +1%
-1.26ms - +0.61ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local3.03ms - 3.04ms-unsure 🔍
-0% - +0%
-0.00ms - +0.01ms
preact-main3.03ms - 3.04msunsure 🔍
-0% - +0%
-0.01ms - +0.00ms
-

run-warmup-0

VersionAvg timevs preact-localvs preact-main
preact-local26.23ms - 26.82ms-unsure 🔍
-3% - +1%
-0.70ms - +0.17ms
preact-main26.47ms - 27.11msunsure 🔍
-1% - +3%
-0.17ms - +0.70ms
-

run-warmup-1

VersionAvg timevs preact-localvs preact-main
preact-local31.60ms - 32.57ms-unsure 🔍
-3% - +1%
-1.12ms - +0.33ms
preact-main31.94ms - 33.01msunsure 🔍
-1% - +3%
-0.33ms - +1.12ms
-

run-warmup-2

VersionAvg timevs preact-localvs preact-main
preact-local31.26ms - 32.61ms-unsure 🔍
-2% - +4%
-0.59ms - +1.34ms
preact-main30.87ms - 32.25msunsure 🔍
-4% - +2%
-1.34ms - +0.59ms
-

run-warmup-3

VersionAvg timevs preact-localvs preact-main
preact-local25.83ms - 26.03ms-unsure 🔍
-0% - +1%
-0.05ms - +0.25ms
preact-main25.72ms - 25.94msunsure 🔍
-1% - +0%
-0.25ms - +0.05ms
-

run-warmup-4

VersionAvg timevs preact-localvs preact-main
preact-local26.03ms - 26.92ms-unsure 🔍
-2% - +3%
-0.42ms - +0.84ms
preact-main25.81ms - 26.71msunsure 🔍
-3% - +2%
-0.84ms - +0.42ms
-

run-final

VersionAvg timevs preact-localvs preact-main
preact-local21.20ms - 21.54ms-unsure 🔍
-2% - +1%
-0.35ms - +0.20ms
preact-main21.23ms - 21.66msunsure 🔍
-1% - +2%
-0.20ms - +0.35ms
-
text-update
  • Browser: chrome-headless
  • Sample size: 210
  • Built by: CI #5817
  • Commit: c0c3646

duration

VersionAvg timevs preact-localvs preact-main
preact-local1.93ms - 2.06ms-unsure 🔍
-6% - +3%
-0.11ms - +0.05ms
preact-main1.97ms - 2.08msunsure 🔍
-3% - +6%
-0.05ms - +0.11ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local1.09ms - 1.16ms-unsure 🔍
-2% - +6%
-0.02ms - +0.07ms
preact-main1.07ms - 1.13msunsure 🔍
-6% - +2%
-0.07ms - +0.02ms
-
todo

duration

VersionAvg timevs preact-localvs preact-main
preact-local31.66ms - 32.67ms-unsure 🔍
-1% - +2%
-0.26ms - +0.79ms
preact-main31.75ms - 32.04msunsure 🔍
-2% - +1%
-0.79ms - +0.26ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local1.28ms - 1.28ms-unsure 🔍
-0% - -0%
-0.00ms - -0.00ms
preact-main1.28ms - 1.28msunsure 🔍
+0% - +0%
+0.00ms - +0.00ms
-
update10th1k

duration

VersionAvg timevs preact-localvs preact-main
preact-local30.70ms - 32.52ms-unsure 🔍
-5% - +3%
-1.47ms - +1.08ms
preact-main30.91ms - 32.70msunsure 🔍
-3% - +5%
-1.08ms - +1.47ms
-

usedJSHeapSize

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

tachometer-reporter-action v2 for CI

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Size Change: -5 B (-0.03%)

Total Size: 15.9 kB

📦 View Changed
Filename Size Change
dist/preact.mjs 4.95 kB -5 B (-0.1%)
ℹ️ View Unchanged
Filename Size
compat/dist/compat.mjs 3.89 kB
debug/dist/debug.mjs 3.88 kB
devtools/dist/devtools.mjs 274 B
hooks/dist/hooks.mjs 1.56 kB
jsx-runtime/dist/jsxRuntime.mjs 856 B
test-utils/dist/testUtils.mjs 473 B

compressed-size-action

@JoviDeCroock
JoviDeCroock force-pushed the JoviDeCroock/issue-2618-algo-learnings branch from 9e45692 to ea85854 Compare August 7, 2026 03:54
Every normalization branch in the loop wrote through
`newParentVNode._children[i]`, reloading the property each time. Bind
it once and write through the local instead.

-5 B brotli (4582 -> 4577), performance-neutral across update, mount,
keyed-reorder and hydration benchmarks.

This replaces the earlier "avoid allocating arrays for single children"
approach from this branch. Passing the single child unwrapped did win
3-7% on update10th1k, but it cost ~3% on first-paint hydration, so it
was dropped.

For the record, hydrate1k's reported 45-55% regression on that earlier
version was a measurement artifact, not a throughput regression: the
benchmark does exactly 5 warmup hydrations and times the 6th, and each
iteration clones and discards ~8000 DOM nodes, which produces a
deterministic periodic slow hydration every ~4-5 iterations. Each build
has its own phase. Timing only #6 sampled the patched build's slow
phase. Holding the build pair fixed and varying only the warmup count
gave -16.8% / +30.8% / +6.4% / +0.9% / -21.8% / +7.0% for hydrations
5-10 (mean ~+1%), while a main-vs-main control over the same protocol
stayed flat at +0.2% / -0.5% / -1.3%.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@JoviDeCroock
JoviDeCroock force-pushed the JoviDeCroock/issue-2618-algo-learnings branch from ea85854 to 16c12ed Compare August 7, 2026 03:57
@JoviDeCroock JoviDeCroock changed the title Avoid allocating arrays for single children Hoist _children into a local in constructNewChildrenArray Aug 7, 2026
@coveralls

coveralls commented Aug 7, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 99.297%. remained the same — JoviDeCroock/issue-2618-algo-learnings into main

@JoviDeCroock
JoviDeCroock marked this pull request as ready for review August 7, 2026 04:02
@JoviDeCroock
JoviDeCroock merged commit 5240c7d into main Aug 7, 2026
13 checks passed
@JoviDeCroock
JoviDeCroock deleted the JoviDeCroock/issue-2618-algo-learnings branch August 7, 2026 09:16
@JoviDeCroock JoviDeCroock mentioned this pull request Aug 8, 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.

3 participants