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

Switch to setTimeout #3607

Merged
merged 1 commit into from
Jul 7, 2022
Merged

Switch to setTimeout #3607

merged 1 commit into from
Jul 7, 2022

Conversation

JoviDeCroock
Copy link
Member

@JoviDeCroock JoviDeCroock commented Jul 7, 2022

This improves the general correctness of DOM-events in Preact, micro-ticks are fired in-between events bubbling up and events firing. This means that when two similar events fire and both are setting state that one will fire set state rerender and then the other one will. Similarly if we fire an event that sets some dom and the ancestor of this eventTarget also has a similar listener after dom manipulation we will bubble up and refire the event....

We could leverage other DOM-techniques like requestIdleCallback but generally this seems to be a lot buggier, the only other thing left would be to write our own scheduler or use the DOM-scheduler API which looks experimental

Example issues
#3596
#2887
#2745

This improves the general correctness of DOM-events in Preact, micro-ticks are fired in-between events bubbling up and events firing. This means that when two similar events fire and both are setting state that one will fire set state rerender and then the other one will. Similarly if we fire an event that sets some dom and the ancestor of this eventTarget also has a similar listener _after_ dom manipulation we will bubble up and refire the event....
@JoviDeCroock JoviDeCroock marked this pull request as ready for review July 7, 2022 07:44
@github-actions
Copy link

github-actions bot commented Jul 7, 2022

📊 Tachometer Benchmark Results

Summary

duration

  • 07_create10k: faster ✔ 1% - 2% (8.11ms - 25.97ms)
    preact-local vs preact-master
  • filter_list: unsure 🔍 -1% - +1% (-2.40ms - +4.49ms)
    preact-local vs preact-master
  • many_updates: unsure 🔍 -4% - +1% (-9.97ms - +2.48ms)
    preact-local vs preact-master
  • text_update: unsure 🔍 -1% - +0% (-0.57ms - +0.17ms)
    preact-local vs preact-master
  • todo: unsure 🔍 -2% - +2% (-1.17ms - +0.98ms)
    preact-local vs preact-master

usedJSHeapSize

  • 07_create10k: slower ❌ 0% - 1% (0.12ms - 0.24ms)
    preact-local vs preact-master
  • filter_list: unsure 🔍 -0% - +0% (-0.00ms - +0.00ms)
    preact-local vs preact-master
  • many_updates: unsure 🔍 -0% - +0% (-0.00ms - +0.01ms)
    preact-local vs preact-master
  • text_update: unsure 🔍 -1% - +0% (-0.01ms - +0.00ms)
    preact-local vs preact-master
  • todo: slower ❌ 0% - 5% (0.01ms - 0.07ms)
    preact-local vs preact-master

Results

07_create10k

duration

VersionAvg timevs preact-mastervs preact-local
preact-master1358.75ms - 1370.01ms-slower ❌
1% - 2%
8.11ms - 25.97ms
preact-local1340.40ms - 1354.26msfaster ✔
1% - 2%
8.11ms - 25.97ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-local
preact-master28.34ms - 28.38ms-faster ✔
0% - 1%
0.12ms - 0.24ms
preact-local28.48ms - 28.59msslower ❌
0% - 1%
0.12ms - 0.24ms
-
filter_list

duration

VersionAvg timevs preact-mastervs preact-local
preact-master314.56ms - 319.42ms-unsure 🔍
-1% - +1%
-4.49ms - +2.40ms
preact-local315.59ms - 320.48msunsure 🔍
-1% - +1%
-2.40ms - +4.49ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-local
preact-master2.14ms - 2.14ms-unsure 🔍
-0% - +0%
-0.00ms - +0.00ms
preact-local2.14ms - 2.14msunsure 🔍
-0% - +0%
-0.00ms - +0.00ms
-
many_updates

duration

VersionAvg timevs preact-mastervs preact-local
preact-master234.13ms - 242.64ms-unsure 🔍
-1% - +4%
-2.48ms - +9.97ms
preact-local230.10ms - 239.18msunsure 🔍
-4% - +1%
-9.97ms - +2.48ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-local
preact-master5.77ms - 5.77ms-unsure 🔍
-0% - +0%
-0.01ms - +0.00ms
preact-local5.77ms - 5.78msunsure 🔍
-0% - +0%
-0.00ms - +0.01ms
-
text_update

duration

VersionAvg timevs preact-mastervs preact-local
preact-master51.15ms - 51.57ms-unsure 🔍
-0% - +1%
-0.17ms - +0.57ms
preact-local50.87ms - 51.46msunsure 🔍
-1% - +0%
-0.57ms - +0.17ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-local
preact-master1.31ms - 1.32ms-unsure 🔍
-0% - +1%
-0.00ms - +0.01ms
preact-local1.31ms - 1.32msunsure 🔍
-1% - +0%
-0.01ms - +0.00ms
-
todo

duration

VersionAvg timevs preact-mastervs preact-local
preact-master50.96ms - 52.24ms-unsure 🔍
-2% - +2%
-0.98ms - +1.17ms
preact-local50.64ms - 52.37msunsure 🔍
-2% - +2%
-1.17ms - +0.98ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-local
preact-master1.38ms - 1.43ms-faster ✔
0% - 5%
0.01ms - 0.07ms
preact-local1.42ms - 1.46msslower ❌
0% - 5%
0.01ms - 0.07ms
-

tachometer-reporter-action v2 for Benchmarks

@github-actions
Copy link

github-actions bot commented Jul 7, 2022

Size Change: -11 B (0%)

Total Size: 37.9 kB

Filename Size Change
dist/preact.js 4.58 kB -4 B (0%)
dist/preact.min.js 4.63 kB -5 B (0%)
dist/preact.umd.js 4.66 kB -2 B (0%)
ℹ️ View Unchanged
Filename Size Change
compat/dist/compat.js 3.75 kB 0 B
compat/dist/compat.umd.js 3.83 kB 0 B
debug/dist/debug.js 3.08 kB 0 B
debug/dist/debug.umd.js 3.17 kB 0 B
devtools/dist/devtools.js 232 B 0 B
devtools/dist/devtools.umd.js 316 B 0 B
hooks/dist/hooks.js 1.29 kB 0 B
hooks/dist/hooks.umd.js 1.38 kB 0 B
jsx-runtime/dist/jsxRuntime.js 342 B 0 B
jsx-runtime/dist/jsxRuntime.umd.js 425 B 0 B
server/dist/server.js 2.6 kB 0 B
server/dist/server.umd.js 2.69 kB 0 B
test-utils/dist/testUtils.js 437 B 0 B
test-utils/dist/testUtils.umd.js 522 B 0 B

compressed-size-action

@coveralls
Copy link

Coverage Status

Coverage remained the same at 99.448% when pulling a07458e on switch-timeout into 580cbad on main.

@marvinhagemeister marvinhagemeister merged commit e903a0e into main Jul 7, 2022
@marvinhagemeister marvinhagemeister deleted the switch-timeout branch July 7, 2022 08:56
JoviDeCroock added a commit that referenced this pull request Jul 7, 2022
This fixes a lot of issues with events as outlined in #3607
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