Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix forceUpdate edge cases #4048

Merged

Conversation

dmitrage
Copy link
Contributor

For context: I use Preact with custom reactivity integration which makes heavy use of forceUpdate and shouldComponentUpdate.

While trying different approaches I've found two issues with forceUpdate and especially the _force flag. Minimal test case is created for each.

  1. _force flag is reset after render and diffChildren are completed. Example: parent component is forceUpdated during child component creation. In this case parent component is re-enqueued but at the time of re-rendering it will have _force flag reset and because of that shouldComponentUpdate will be called while it should not. Resetting this flag before rendering resolves this issue.

  2. _force flag is ignored in strict-equality bail-out. Example: parent component caches render result to benefit from bail out, parent and child components are both forceUpdated. In this case bail out resets the _force flag and child component shouldComponentUpdate is called while it should not. Not bailing out on forceUpdated components resolves this issue. But I'm afraid I miss the reason why it was allowed before.

Workaround I use for both cases:

  • Set additional isForceUpdate flag when calling forceUpdate
  • Return true in shouldComponentUpdate if this flag is set
  • Reset this flag in render

@github-actions
Copy link

github-actions bot commented Jun 16, 2023

📊 Tachometer Benchmark Results

Summary

duration

  • 02_replace1k: unsure 🔍 -1% - +2% (-1.67ms - +1.93ms)
    preact-local vs preact-master
  • 03_update10th1k_x16: unsure 🔍 -4% - +5% (-1.40ms - +1.61ms)
    preact-local vs preact-master
  • 07_create10k: unsure 🔍 -1% - +0% (-12.37ms - +2.62ms)
    preact-local vs preact-master
  • filter_list: unsure 🔍 -2% - +4% (-0.76ms - +1.32ms)
    preact-local vs preact-master
  • hydrate1k: unsure 🔍 -1% - +0% (-1.45ms - +0.50ms)
    preact-local vs preact-master
  • many_updates: unsure 🔍 -3% - +1% (-0.88ms - +0.20ms)
    preact-local vs preact-master
  • text_update: unsure 🔍 -2% - +1% (-0.06ms - +0.04ms)
    preact-local vs preact-master
  • todo: unsure 🔍 -4% - +1% (-2.64ms - +0.54ms)
    preact-local vs preact-master

usedJSHeapSize

  • 02_replace1k: unsure 🔍 -0% - +0% (-0.01ms - +0.01ms)
    preact-local vs preact-master
  • 03_update10th1k_x16: unsure 🔍 -0% - +0% (-0.01ms - +0.00ms)
    preact-local vs preact-master
  • 07_create10k: unsure 🔍 -0% - +0% (-0.00ms - +0.00ms)
    preact-local vs preact-master
  • filter_list: unsure 🔍 -2% - +2% (-0.03ms - +0.03ms)
    preact-local vs preact-master
  • hydrate1k: unsure 🔍 -0% - +1% (-0.03ms - +0.03ms)
    preact-local vs preact-master
  • many_updates: unsure 🔍 -1% - +1% (-0.02ms - +0.04ms)
    preact-local vs preact-master
  • text_update: unsure 🔍 -1% - +0% (-0.01ms - +0.00ms)
    preact-local vs preact-master
  • todo: unsure 🔍 -2% - +2% (-0.01ms - +0.02ms)
    preact-local vs preact-master

Results

02_replace1k

duration

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master127.14ms - 129.76ms-unsure 🔍
-1% - +1%
-1.93ms - +1.67ms
unsure 🔍
-2% - +1%
-2.16ms - +1.62ms
preact-local127.34ms - 129.81msunsure 🔍
-1% - +2%
-1.67ms - +1.93ms
-unsure 🔍
-2% - +1%
-1.98ms - +1.69ms
preact-hooks127.36ms - 130.08msunsure 🔍
-1% - +2%
-1.62ms - +2.16ms
unsure 🔍
-1% - +2%
-1.69ms - +1.98ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master3.28ms - 3.29ms-unsure 🔍
-0% - +0%
-0.01ms - +0.01ms
faster ✔
1% - 1%
0.02ms - 0.04ms
preact-local3.28ms - 3.30msunsure 🔍
-0% - +0%
-0.01ms - +0.01ms
-faster ✔
0% - 1%
0.01ms - 0.04ms
preact-hooks3.31ms - 3.32msslower ❌
1% - 1%
0.02ms - 0.04ms
slower ❌
0% - 1%
0.01ms - 0.04ms
-

run-warmup-0

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master45.10ms - 47.35ms-unsure 🔍
-5% - +2%
-2.14ms - +0.91ms
unsure 🔍
-5% - +2%
-2.12ms - +0.76ms
preact-local45.81ms - 47.88msunsure 🔍
-2% - +5%
-0.91ms - +2.14ms
-unsure 🔍
-3% - +3%
-1.44ms - +1.31ms
preact-hooks46.00ms - 47.81msunsure 🔍
-2% - +5%
-0.76ms - +2.12ms
unsure 🔍
-3% - +3%
-1.31ms - +1.44ms
-

run-warmup-1

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master57.91ms - 60.25ms-unsure 🔍
-3% - +3%
-1.49ms - +1.63ms
unsure 🔍
-3% - +2%
-1.90ms - +1.22ms
preact-local57.97ms - 60.05msunsure 🔍
-3% - +3%
-1.63ms - +1.49ms
-unsure 🔍
-3% - +2%
-1.88ms - +1.06ms
preact-hooks58.38ms - 60.45msunsure 🔍
-2% - +3%
-1.22ms - +1.90ms
unsure 🔍
-2% - +3%
-1.06ms - +1.88ms
-

run-warmup-2

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master47.01ms - 50.13ms-unsure 🔍
-6% - +3%
-2.85ms - +1.34ms
unsure 🔍
-6% - +3%
-2.73ms - +1.70ms
preact-local47.93ms - 50.72msunsure 🔍
-3% - +6%
-1.34ms - +2.85ms
-unsure 🔍
-4% - +5%
-1.87ms - +2.35ms
preact-hooks47.51ms - 50.66msunsure 🔍
-4% - +6%
-1.70ms - +2.73ms
unsure 🔍
-5% - +4%
-2.35ms - +1.87ms
-

run-warmup-3

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master39.03ms - 41.81ms-unsure 🔍
-6% - +4%
-2.36ms - +1.83ms
faster ✔
1% - 12%
0.50ms - 5.14ms
preact-local39.12ms - 42.26msunsure 🔍
-5% - +6%
-1.83ms - +2.36ms
-faster ✔
0% - 11%
0.13ms - 4.99ms
preact-hooks41.39ms - 45.10msslower ❌
1% - 13%
0.50ms - 5.14ms
slower ❌
0% - 12%
0.13ms - 4.99ms
-

run-warmup-4

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master48.69ms - 51.09ms-unsure 🔍
-3% - +4%
-1.67ms - +2.02ms
unsure 🔍
-4% - +3%
-2.04ms - +1.54ms
preact-local48.32ms - 51.12msunsure 🔍
-4% - +3%
-2.02ms - +1.67ms
-unsure 🔍
-5% - +3%
-2.36ms - +1.51ms
preact-hooks48.81ms - 51.47msunsure 🔍
-3% - +4%
-1.54ms - +2.04ms
unsure 🔍
-3% - +5%
-1.51ms - +2.36ms
-

run-final

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master31.98ms - 33.70ms-unsure 🔍
-5% - +3%
-1.59ms - +0.85ms
unsure 🔍
-4% - +3%
-1.35ms - +1.02ms
preact-local32.34ms - 34.07msunsure 🔍
-3% - +5%
-0.85ms - +1.59ms
-unsure 🔍
-3% - +4%
-0.98ms - +1.40ms
preact-hooks32.18ms - 33.82msunsure 🔍
-3% - +4%
-1.02ms - +1.35ms
unsure 🔍
-4% - +3%
-1.40ms - +0.98ms
-
03_update10th1k_x16

duration

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master32.88ms - 34.98ms-unsure 🔍
-5% - +4%
-1.61ms - +1.40ms
unsure 🔍
-5% - +4%
-1.66ms - +1.43ms
preact-local32.96ms - 35.11msunsure 🔍
-4% - +5%
-1.40ms - +1.61ms
-unsure 🔍
-5% - +5%
-1.58ms - +1.56ms
preact-hooks32.91ms - 35.18msunsure 🔍
-4% - +5%
-1.43ms - +1.66ms
unsure 🔍
-5% - +5%
-1.56ms - +1.58ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master3.24ms - 3.25ms-unsure 🔍
-0% - +0%
-0.00ms - +0.01ms
faster ✔
0% - 1%
0.01ms - 0.03ms
preact-local3.24ms - 3.25msunsure 🔍
-0% - +0%
-0.01ms - +0.00ms
-faster ✔
1% - 1%
0.02ms - 0.03ms
preact-hooks3.26ms - 3.27msslower ❌
0% - 1%
0.01ms - 0.03ms
slower ❌
1% - 1%
0.02ms - 0.03ms
-
07_create10k

duration

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master1285.21ms - 1297.66ms-unsure 🔍
-0% - +1%
-2.62ms - +12.37ms
unsure 🔍
-1% - +1%
-7.36ms - +7.94ms
preact-local1282.37ms - 1290.74msunsure 🔍
-1% - +0%
-12.37ms - +2.62ms
-unsure 🔍
-1% - +0%
-10.70ms - +1.52ms
preact-hooks1286.69ms - 1295.60msunsure 🔍
-1% - +1%
-7.94ms - +7.36ms
unsure 🔍
-0% - +1%
-1.52ms - +10.70ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master25.32ms - 25.32ms-unsure 🔍
-0% - +0%
-0.00ms - +0.00ms
unsure 🔍
-0% - -0%
-0.02ms - -0.02ms
preact-local25.32ms - 25.32msunsure 🔍
-0% - +0%
-0.00ms - +0.00ms
-unsure 🔍
-0% - -0%
-0.02ms - -0.02ms
preact-hooks25.34ms - 25.34msunsure 🔍
+0% - +0%
+0.02ms - +0.02ms
unsure 🔍
+0% - +0%
+0.02ms - +0.02ms
-
filter_list

duration

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master32.49ms - 33.61ms-unsure 🔍
-4% - +2%
-1.32ms - +0.76ms
unsure 🔍
-3% - +3%
-1.09ms - +0.86ms
preact-local32.45ms - 34.20msunsure 🔍
-2% - +4%
-0.76ms - +1.32ms
-unsure 🔍
-3% - +4%
-1.02ms - +1.35ms
preact-hooks32.36ms - 33.96msunsure 🔍
-3% - +3%
-0.86ms - +1.09ms
unsure 🔍
-4% - +3%
-1.35ms - +1.02ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master1.41ms - 1.44ms-unsure 🔍
-2% - +2%
-0.03ms - +0.03ms
unsure 🔍
-4% - +0%
-0.05ms - +0.00ms
preact-local1.41ms - 1.45msunsure 🔍
-2% - +2%
-0.03ms - +0.03ms
-unsure 🔍
-4% - +0%
-0.05ms - +0.01ms
preact-hooks1.43ms - 1.47msunsure 🔍
-0% - +4%
-0.00ms - +0.05ms
unsure 🔍
-1% - +4%
-0.01ms - +0.05ms
-
hydrate1k

duration

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master112.94ms - 114.36ms-unsure 🔍
-0% - +1%
-0.50ms - +1.45ms
unsure 🔍
-2% - +0%
-1.90ms - +0.25ms
preact-local112.50ms - 113.85msunsure 🔍
-1% - +0%
-1.45ms - +0.50ms
-faster ✔
0% - 2%
0.25ms - 2.35ms
preact-hooks113.67ms - 115.29msunsure 🔍
-0% - +2%
-0.25ms - +1.90ms
slower ❌
0% - 2%
0.25ms - 2.35ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master5.96ms - 6.00ms-unsure 🔍
-1% - +0%
-0.03ms - +0.03ms
faster ✔
0% - 1%
0.01ms - 0.07ms
preact-local5.96ms - 6.00msunsure 🔍
-0% - +1%
-0.03ms - +0.03ms
-faster ✔
0% - 1%
0.01ms - 0.07ms
preact-hooks6.00ms - 6.04msslower ❌
0% - 1%
0.01ms - 0.07ms
slower ❌
0% - 1%
0.01ms - 0.07ms
-
many_updates

duration

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master25.43ms - 26.13ms-unsure 🔍
-1% - +3%
-0.20ms - +0.88ms
unsure 🔍
-3% - +1%
-0.75ms - +0.37ms
preact-local25.02ms - 25.85msunsure 🔍
-3% - +1%
-0.88ms - +0.20ms
-unsure 🔍
-4% - +0%
-1.14ms - +0.07ms
preact-hooks25.53ms - 26.41msunsure 🔍
-1% - +3%
-0.37ms - +0.75ms
unsure 🔍
-0% - +4%
-0.07ms - +1.14ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master4.47ms - 4.51ms-unsure 🔍
-1% - +1%
-0.04ms - +0.02ms
unsure 🔍
-1% - +0%
-0.04ms - +0.02ms
preact-local4.48ms - 4.52msunsure 🔍
-1% - +1%
-0.02ms - +0.04ms
-unsure 🔍
-1% - +0%
-0.03ms - +0.02ms
preact-hooks4.49ms - 4.52msunsure 🔍
-0% - +1%
-0.02ms - +0.04ms
unsure 🔍
-0% - +1%
-0.02ms - +0.03ms
-
text_update

duration

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master2.66ms - 2.73ms-unsure 🔍
-1% - +2%
-0.04ms - +0.06ms
faster ✔
4% - 8%
0.12ms - 0.24ms
preact-local2.65ms - 2.72msunsure 🔍
-2% - +1%
-0.06ms - +0.04ms
-faster ✔
4% - 9%
0.13ms - 0.25ms
preact-hooks2.82ms - 2.93msslower ❌
4% - 9%
0.12ms - 0.24ms
slower ❌
5% - 10%
0.13ms - 0.25ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master0.62ms - 0.63ms-unsure 🔍
-0% - +1%
-0.00ms - +0.01ms
faster ✔
9% - 11%
0.06ms - 0.08ms
preact-local0.62ms - 0.62msunsure 🔍
-1% - +0%
-0.01ms - +0.00ms
-faster ✔
10% - 11%
0.07ms - 0.08ms
preact-hooks0.69ms - 0.70msslower ❌
10% - 13%
0.06ms - 0.08ms
slower ❌
11% - 13%
0.07ms - 0.08ms
-
todo

duration

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master61.35ms - 63.35ms-unsure 🔍
-1% - +4%
-0.54ms - +2.64ms
faster ✔
6% - 11%
4.09ms - 7.54ms
preact-local60.07ms - 62.54msunsure 🔍
-4% - +1%
-2.64ms - +0.54ms
-faster ✔
7% - 13%
4.99ms - 8.73ms
preact-hooks66.76ms - 69.57msslower ❌
6% - 12%
4.09ms - 7.54ms
slower ❌
8% - 14%
4.99ms - 8.73ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master0.85ms - 0.87ms-unsure 🔍
-2% - +2%
-0.02ms - +0.01ms
faster ✔
2% - 4%
0.02ms - 0.04ms
preact-local0.85ms - 0.87msunsure 🔍
-2% - +2%
-0.01ms - +0.02ms
-faster ✔
2% - 4%
0.02ms - 0.03ms
preact-hooks0.88ms - 0.89msslower ❌
2% - 4%
0.02ms - 0.04ms
slower ❌
2% - 4%
0.02ms - 0.03ms
-

tachometer-reporter-action v2 for Benchmarks

@coveralls
Copy link

coveralls commented Jun 19, 2023

Coverage Status

coverage: 99.706%. remained the same when pulling f1eed0e on dmitrage:may-the-force-be-with-you into d887539 on preactjs:master.

Copy link
Member

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

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

Awesome, thank you so much for fixing this! This is a really well done PR ❤️

@marvinhagemeister marvinhagemeister merged commit 523bbe9 into preactjs:master Jun 19, 2023
13 checks passed
@JoviDeCroock JoviDeCroock mentioned this pull request Jul 8, 2023
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.

None yet

3 participants