Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(hooks): memo being too lazy with repeated renders #4426

Merged
merged 2 commits into from
Jun 28, 2024
Merged

Conversation

JoviDeCroock
Copy link
Member

@JoviDeCroock JoviDeCroock commented Jun 28, 2024

This now equalises our behavior with React, we need to ensure that when we repeat a render we throwaway queued effects, this is done in _render. We however want to maintain achieved hook-states for i.e. useMemo as they are synchronous anyway, React seems to achieve this by disposing the WIP but retaining hooks-state. This PR makes us behave similarly.

Fixes #4422

Copy link

github-actions bot commented Jun 28, 2024

📊 Tachometer Benchmark Results

Summary

duration

  • create10k: unsure 🔍 -1% - +0% (-7.46ms - +2.92ms)
    preact-local vs preact-main
  • filter-list: unsure 🔍 -0% - +1% (-0.08ms - +0.17ms)
    preact-local vs preact-main
  • hydrate1k: unsure 🔍 -4% - +5% (-2.58ms - +3.34ms)
    preact-local vs preact-main
  • many-updates: unsure 🔍 -1% - +3% (-0.08ms - +0.54ms)
    preact-local vs preact-main
  • replace1k: unsure 🔍 -3% - +2% (-2.01ms - +1.70ms)
    preact-local vs preact-main
  • text-update: unsure 🔍 -5% - +4% (-0.09ms - +0.08ms)
    preact-local vs preact-main
  • todo: unsure 🔍 -0% - +1% (-0.02ms - +0.36ms)
    preact-local vs preact-main
  • update10th1k: unsure 🔍 -3% - +1% (-1.10ms - +0.26ms)
    preact-local vs preact-main

usedJSHeapSize

  • create10k: unsure 🔍 -0% - +0% (-0.02ms - +0.00ms)
    preact-local vs preact-main
  • filter-list: unsure 🔍 -0% - +0% (-0.00ms - +0.00ms)
    preact-local vs preact-main
  • hydrate1k: unsure 🔍 -1% - +2% (-0.17ms - +0.25ms)
    preact-local vs preact-main
  • many-updates: unsure 🔍 -0% - +0% (-0.00ms - +0.00ms)
    preact-local vs preact-main
  • replace1k: unsure 🔍 -1% - +0% (-0.03ms - +0.01ms)
    preact-local vs preact-main
  • text-update: unsure 🔍 -0% - +1% (-0.00ms - +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.00ms - +0.00ms)
    preact-local vs preact-main

Results

create10k

duration

VersionAvg timevs preact-localvs preact-main
preact-local859.96ms - 865.01ms-unsure 🔍
-1% - +0%
-7.46ms - +2.92ms
preact-main860.23ms - 869.29msunsure 🔍
-0% - +1%
-2.92ms - +7.46ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local25.15ms - 25.15ms-unsure 🔍
-0% - +0%
-0.02ms - +0.00ms
preact-main25.15ms - 25.17msunsure 🔍
-0% - +0%
-0.00ms - +0.02ms
-
filter-list

duration

VersionAvg timevs preact-localvs preact-main
preact-local16.67ms - 16.87ms-unsure 🔍
-0% - +1%
-0.08ms - +0.17ms
preact-main16.66ms - 16.79msunsure 🔍
-1% - +0%
-0.17ms - +0.08ms
-

usedJSHeapSize

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

duration

VersionAvg timevs preact-localvs preact-main
preact-local68.81ms - 73.16ms-unsure 🔍
-4% - +5%
-2.58ms - +3.34ms
preact-main68.60ms - 72.62msunsure 🔍
-5% - +4%
-3.34ms - +2.58ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local13.14ms - 13.47ms-unsure 🔍
-1% - +2%
-0.17ms - +0.25ms
preact-main13.13ms - 13.40msunsure 🔍
-2% - +1%
-0.25ms - +0.17ms
-
many-updates

duration

VersionAvg timevs preact-localvs preact-main
preact-local16.48ms - 17.08ms-unsure 🔍
-1% - +3%
-0.08ms - +0.54ms
preact-main16.47ms - 16.64msunsure 🔍
-3% - +0%
-0.54ms - +0.08ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local4.61ms - 4.61ms-unsure 🔍
-0% - +0%
-0.00ms - +0.00ms
preact-main4.61ms - 4.61msunsure 🔍
-0% - +0%
-0.00ms - +0.00ms
-
replace1k

duration

VersionAvg timevs preact-localvs preact-main
preact-local76.03ms - 78.63ms-unsure 🔍
-3% - +2%
-2.01ms - +1.70ms
preact-main76.17ms - 78.81msunsure 🔍
-2% - +3%
-1.70ms - +2.01ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local3.51ms - 3.54ms-unsure 🔍
-1% - +0%
-0.03ms - +0.01ms
preact-main3.52ms - 3.55msunsure 🔍
-0% - +1%
-0.01ms - +0.03ms
-

run-warmup-0

VersionAvg timevs preact-localvs preact-main
preact-local29.30ms - 29.88ms-unsure 🔍
-0% - +3%
-0.05ms - +0.79ms
preact-main28.92ms - 29.52msunsure 🔍
-3% - +0%
-0.79ms - +0.05ms
-

run-warmup-1

VersionAvg timevs preact-localvs preact-main
preact-local34.93ms - 36.83ms-unsure 🔍
-1% - +7%
-0.37ms - +2.33ms
preact-main33.94ms - 35.86msunsure 🔍
-6% - +1%
-2.33ms - +0.37ms
-

run-warmup-2

VersionAvg timevs preact-localvs preact-main
preact-local25.63ms - 26.23ms-unsure 🔍
-1% - +2%
-0.28ms - +0.48ms
preact-main25.60ms - 26.07msunsure 🔍
-2% - +1%
-0.48ms - +0.28ms
-

run-warmup-3

VersionAvg timevs preact-localvs preact-main
preact-local30.01ms - 31.58ms-unsure 🔍
-5% - +2%
-1.68ms - +0.49ms
preact-main30.65ms - 32.14msunsure 🔍
-2% - +5%
-0.49ms - +1.68ms
-

run-warmup-4

VersionAvg timevs preact-localvs preact-main
preact-local23.04ms - 24.79ms-unsure 🔍
-3% - +7%
-0.73ms - +1.72ms
preact-main22.56ms - 24.27msunsure 🔍
-7% - +3%
-1.72ms - +0.73ms
-

run-final

VersionAvg timevs preact-localvs preact-main
preact-local23.59ms - 24.60ms-unsure 🔍
-4% - +2%
-0.88ms - +0.59ms
preact-main23.71ms - 24.77msunsure 🔍
-2% - +4%
-0.59ms - +0.88ms
-
text-update

duration

VersionAvg timevs preact-localvs preact-main
preact-local1.98ms - 2.12ms-unsure 🔍
-5% - +4%
-0.09ms - +0.08ms
preact-main2.00ms - 2.11msunsure 🔍
-4% - +5%
-0.08ms - +0.09ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local0.98ms - 0.99ms-unsure 🔍
-0% - +1%
-0.00ms - +0.01ms
preact-main0.98ms - 0.98msunsure 🔍
-1% - +0%
-0.01ms - +0.00ms
-
todo

duration

VersionAvg timevs preact-localvs preact-main
preact-local27.29ms - 27.58ms-unsure 🔍
-0% - +1%
-0.02ms - +0.36ms
preact-main27.14ms - 27.39msunsure 🔍
-1% - +0%
-0.36ms - +0.02ms
-

usedJSHeapSize

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

duration

VersionAvg timevs preact-localvs preact-main
preact-local35.17ms - 35.89ms-unsure 🔍
-3% - +1%
-1.10ms - +0.26ms
preact-main35.38ms - 36.53msunsure 🔍
-1% - +3%
-0.26ms - +1.10ms
-

usedJSHeapSize

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

tachometer-reporter-action v2 for Benchmarks

expect(calls).to.deep.equal([
'doing memo',
'render hi',
'doing memo',
'render bye', // We expect a missing "doing memo" here because we return to the previous args value
Copy link
Member Author

Choose a reason for hiding this comment

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

Justification for change can be found here

Copy link

github-actions bot commented Jun 28, 2024

Size Change: -88 B (-0.14%)

Total Size: 61.7 kB

Filename Size Change
hooks/dist/hooks.js 1.53 kB -28 B (-1.8%)
hooks/dist/hooks.module.js 1.56 kB -30 B (-1.88%)
hooks/dist/hooks.umd.js 1.6 kB -30 B (-1.84%)
ℹ️ View Unchanged
Filename Size
compat/dist/compat.js 4.1 kB
compat/dist/compat.module.js 4.03 kB
compat/dist/compat.umd.js 4.17 kB
debug/dist/debug.js 3.7 kB
debug/dist/debug.module.js 3.71 kB
debug/dist/debug.umd.js 3.78 kB
devtools/dist/devtools.js 259 B
devtools/dist/devtools.module.js 273 B
devtools/dist/devtools.umd.js 345 B
dist/preact.js 4.67 kB
dist/preact.min.js 4.7 kB
dist/preact.min.module.js 4.7 kB
dist/preact.min.umd.js 4.73 kB
dist/preact.module.js 4.7 kB
dist/preact.umd.js 4.75 kB
jsx-runtime/dist/jsxRuntime.js 981 B
jsx-runtime/dist/jsxRuntime.module.js 956 B
jsx-runtime/dist/jsxRuntime.umd.js 1.06 kB
test-utils/dist/testUtils.js 451 B
test-utils/dist/testUtils.module.js 456 B
test-utils/dist/testUtils.umd.js 536 B

compressed-size-action

@@ -477,4 +477,44 @@ describe('combinations', () => {
'anchor effect'
]);
});

it('should not loop infinitely', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

@coveralls
Copy link

Coverage Status

coverage: 99.611%. remained the same
when pulling 0068260 on memo-fix
into eb37677 on main.

@coveralls
Copy link

Coverage Status

coverage: 99.611%. remained the same
when pulling d0daefa on memo-fix
into eb37677 on main.

@coveralls
Copy link

Coverage Status

coverage: 99.611%. remained the same
when pulling 0068260 on memo-fix
into eb37677 on main.

@coveralls
Copy link

Coverage Status

coverage: 99.611%. remained the same
when pulling 0068260 on memo-fix
into eb37677 on main.

@coveralls
Copy link

Coverage Status

coverage: 99.611%. remained the same
when pulling 1209527 on memo-fix
into eb37677 on main.

@coveralls
Copy link

Coverage Status

coverage: 99.611%. remained the same
when pulling 1209527 on memo-fix
into eb37677 on main.

@coveralls
Copy link

Coverage Status

coverage: 99.611%. remained the same
when pulling 1209527 on memo-fix
into eb37677 on main.

@coveralls
Copy link

Coverage Status

coverage: 99.611%. remained the same
when pulling 1209527 on memo-fix
into eb37677 on main.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[preact/hooks] useMemo keeps recalculating even when the dependency is not changed
3 participants