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: use a virtual clock instead of Date.now() for event dispatch times #4322

Merged
merged 1 commit into from
Mar 23, 2024
Merged

fix: use a virtual clock instead of Date.now() for event dispatch times #4322

merged 1 commit into from
Mar 23, 2024

Conversation

jviide
Copy link
Contributor

@jviide jviide commented Mar 23, 2024

This is an alternative solution for issue #4161. It takes the general idea of #4232, but modifies the logic with an extra trick: odd counter values are reserved for e._dispatched and even values for value._attached. This way we can tell whether an event was dispatched between two handler attachments, and vice versa. This in turn allows incrementing the counter only when needed without scheduling a microtask for it.

Fixes #4161.

Copy link

github-actions bot commented Mar 23, 2024

📊 Tachometer Benchmark Results

Summary

duration

  • 02_replace1k: unsure 🔍 -1% - +3% (-0.47ms - +2.27ms)
    preact-local vs preact-main
  • 03_update10th1k_x16: unsure 🔍 -3% - +5% (-0.85ms - +1.38ms)
    preact-local vs preact-main
  • 07_create10k: unsure 🔍 -1% - +1% (-4.55ms - +10.25ms)
    preact-local vs preact-main
  • filter_list: unsure 🔍 -0% - +0% (-0.06ms - +0.04ms)
    preact-local vs preact-main
  • hydrate1k: unsure 🔍 -2% - +1% (-1.73ms - +1.23ms)
    preact-local vs preact-main
  • many_updates: unsure 🔍 -4% - +2% (-0.69ms - +0.26ms)
    preact-local vs preact-main
  • text_update: unsure 🔍 -2% - +3% (-0.04ms - +0.07ms)
    preact-local vs preact-main
  • todo: faster ✔ 0% - 2% (0.11ms - 0.54ms)
    preact-local vs preact-main

usedJSHeapSize

  • 02_replace1k: faster ✔ 0% - 1% (0.01ms - 0.02ms)
    preact-local vs preact-main
  • 03_update10th1k_x16: faster ✔ 1% - 1% (0.02ms - 0.03ms)
    preact-local vs preact-main
  • 07_create10k: faster ✔ 1% - 1% (0.24ms - 0.24ms)
    preact-local vs preact-main
  • filter_list: unsure 🔍 -0% - +0% (-0.00ms - +0.00ms)
    preact-local vs preact-main
  • hydrate1k: faster ✔ 1% - 1% (0.05ms - 0.05ms)
    preact-local vs preact-main
  • many_updates: unsure 🔍 -0% - +0% (-0.00ms - +0.00ms)
    preact-local vs preact-main
  • text_update: unsure 🔍 -0% - +0% (-0.00ms - +0.00ms)
    preact-local vs preact-main
  • todo: unsure 🔍 -0% - +0% (-0.00ms - +0.00ms)
    preact-local vs preact-main

Results

02_replace1k

duration

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main73.89ms - 75.36ms-unsure 🔍
-3% - +1%
-2.27ms - +0.47ms
unsure 🔍
-2% - +0%
-1.74ms - +0.34ms
preact-local74.37ms - 76.68msunsure 🔍
-1% - +3%
-0.47ms - +2.27ms
-unsure 🔍
-2% - +2%
-1.17ms - +1.57ms
preact-hooks74.59ms - 76.06msunsure 🔍
-0% - +2%
-0.34ms - +1.74ms
unsure 🔍
-2% - +2%
-1.57ms - +1.17ms
-

usedJSHeapSize

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main3.40ms - 3.41ms-slower ❌
0% - 1%
0.01ms - 0.02ms
unsure 🔍
-0% - +0%
-0.00ms - +0.00ms
preact-local3.38ms - 3.39msfaster ✔
0% - 1%
0.01ms - 0.02ms
-faster ✔
0% - 1%
0.01ms - 0.02ms
preact-hooks3.40ms - 3.41msunsure 🔍
-0% - +0%
-0.00ms - +0.00ms
slower ❌
0% - 1%
0.01ms - 0.02ms
-

run-warmup-0

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main29.44ms - 30.11ms-unsure 🔍
-1% - +3%
-0.18ms - +0.74ms
unsure 🔍
-3% - +0%
-0.90ms - +0.14ms
preact-local29.19ms - 29.82msunsure 🔍
-2% - +1%
-0.74ms - +0.18ms
-faster ✔
1% - 4%
0.15ms - 1.16ms
preact-hooks29.76ms - 30.55msunsure 🔍
-0% - +3%
-0.14ms - +0.90ms
slower ❌
0% - 4%
0.15ms - 1.16ms
-

run-warmup-1

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main39.64ms - 41.04ms-unsure 🔍
-1% - +4%
-0.55ms - +1.57ms
unsure 🔍
-2% - +2%
-0.90ms - +0.80ms
preact-local39.04ms - 40.63msunsure 🔍
-4% - +1%
-1.57ms - +0.55ms
-unsure 🔍
-4% - +1%
-1.48ms - +0.37ms
preact-hooks39.92ms - 40.86msunsure 🔍
-2% - +2%
-0.80ms - +0.90ms
unsure 🔍
-1% - +4%
-0.37ms - +1.48ms
-

run-warmup-2

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main26.32ms - 26.71ms-unsure 🔍
-0% - +2%
-0.03ms - +0.52ms
unsure 🔍
-1% - +2%
-0.18ms - +0.46ms
preact-local26.07ms - 26.46msunsure 🔍
-2% - +0%
-0.52ms - +0.03ms
-unsure 🔍
-2% - +1%
-0.43ms - +0.21ms
preact-hooks26.12ms - 26.63msunsure 🔍
-2% - +1%
-0.46ms - +0.18ms
unsure 🔍
-1% - +2%
-0.21ms - +0.43ms
-

run-warmup-3

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main24.93ms - 26.01ms-unsure 🔍
-1% - +5%
-0.34ms - +1.19ms
unsure 🔍
-1% - +6%
-0.12ms - +1.51ms
preact-local24.51ms - 25.58msunsure 🔍
-5% - +1%
-1.19ms - +0.34ms
-unsure 🔍
-2% - +4%
-0.54ms - +1.08ms
preact-hooks24.17ms - 25.38msunsure 🔍
-6% - +0%
-1.51ms - +0.12ms
unsure 🔍
-4% - +2%
-1.08ms - +0.54ms
-

run-warmup-4

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main27.26ms - 28.98ms-slower ❌
6% - 15%
1.62ms - 3.67ms
unsure 🔍
-0% - +8%
-0.09ms - +2.04ms
preact-local24.92ms - 26.02msfaster ✔
6% - 13%
1.62ms - 3.67ms
-faster ✔
3% - 9%
0.84ms - 2.51ms
preact-hooks26.52ms - 27.78msunsure 🔍
-7% - +0%
-2.04ms - +0.09ms
slower ❌
3% - 10%
0.84ms - 2.51ms
-

run-final

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main22.80ms - 23.40ms-unsure 🔍
-2% - +3%
-0.35ms - +0.63ms
faster ✔
2% - 6%
0.52ms - 1.55ms
preact-local22.57ms - 23.34msunsure 🔍
-3% - +2%
-0.63ms - +0.35ms
-faster ✔
3% - 7%
0.60ms - 1.75ms
preact-hooks23.71ms - 24.56msslower ❌
2% - 7%
0.52ms - 1.55ms
slower ❌
3% - 8%
0.60ms - 1.75ms
-
03_update10th1k_x16

duration

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main29.74ms - 31.22ms-unsure 🔍
-4% - +3%
-1.38ms - +0.85ms
faster ✔
1% - 8%
0.18ms - 2.46ms
preact-local29.91ms - 31.58msunsure 🔍
-3% - +5%
-0.85ms - +1.38ms
-unsure 🔍
-7% - +0%
-2.26ms - +0.15ms
preact-hooks30.93ms - 32.66msslower ❌
1% - 8%
0.18ms - 2.46ms
unsure 🔍
-1% - +7%
-0.15ms - +2.26ms
-

usedJSHeapSize

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main3.36ms - 3.37ms-slower ❌
1% - 1%
0.02ms - 0.03ms
unsure 🔍
-0% - +0%
-0.01ms - +0.00ms
preact-local3.34ms - 3.35msfaster ✔
1% - 1%
0.02ms - 0.03ms
-faster ✔
1% - 1%
0.02ms - 0.03ms
preact-hooks3.36ms - 3.37msunsure 🔍
-0% - +0%
-0.00ms - +0.01ms
slower ❌
1% - 1%
0.02ms - 0.03ms
-
07_create10k

duration

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main895.63ms - 902.89ms-unsure 🔍
-1% - +1%
-10.25ms - +4.55ms
unsure 🔍
-1% - +0%
-5.37ms - +3.74ms
preact-local895.67ms - 908.55msunsure 🔍
-1% - +1%
-4.55ms - +10.25ms
-unsure 🔍
-1% - +1%
-4.97ms - +9.04ms
preact-hooks897.32ms - 902.83msunsure 🔍
-0% - +1%
-3.74ms - +5.37ms
unsure 🔍
-1% - +1%
-9.04ms - +4.97ms
-

usedJSHeapSize

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main26.40ms - 26.40ms-slower ❌
1% - 1%
0.24ms - 0.24ms
slower ❌
1% - 1%
0.22ms - 0.22ms
preact-local26.16ms - 26.16msfaster ✔
1% - 1%
0.24ms - 0.24ms
-unsure 🔍
-0% - -0%
-0.02ms - -0.02ms
preact-hooks26.18ms - 26.18msfaster ✔
1% - 1%
0.22ms - 0.22ms
unsure 🔍
+0% - +0%
+0.02ms - +0.02ms
-
filter_list

duration

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main16.56ms - 16.65ms-unsure 🔍
-0% - +0%
-0.04ms - +0.06ms
unsure 🔍
-2% - +1%
-0.39ms - +0.18ms
preact-local16.57ms - 16.62msunsure 🔍
-0% - +0%
-0.06ms - +0.04ms
-unsure 🔍
-2% - +1%
-0.39ms - +0.17ms
preact-hooks16.43ms - 16.99msunsure 🔍
-1% - +2%
-0.18ms - +0.39ms
unsure 🔍
-1% - +2%
-0.17ms - +0.39ms
-

usedJSHeapSize

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main1.42ms - 1.42ms-unsure 🔍
-0% - +0%
-0.00ms - +0.00ms
faster ✔
2% - 2%
0.02ms - 0.03ms
preact-local1.42ms - 1.42msunsure 🔍
-0% - +0%
-0.00ms - +0.00ms
-faster ✔
2% - 2%
0.02ms - 0.03ms
preact-hooks1.44ms - 1.45msslower ❌
2% - 2%
0.02ms - 0.03ms
slower ❌
2% - 2%
0.02ms - 0.03ms
-
hydrate1k

duration

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main83.50ms - 85.72ms-unsure 🔍
-1% - +2%
-1.23ms - +1.73ms
unsure 🔍
-2% - +2%
-1.51ms - +1.41ms
preact-local83.38ms - 85.34msunsure 🔍
-2% - +1%
-1.73ms - +1.23ms
-unsure 🔍
-2% - +1%
-1.66ms - +1.06ms
preact-hooks83.71ms - 85.61msunsure 🔍
-2% - +2%
-1.41ms - +1.51ms
unsure 🔍
-1% - +2%
-1.06ms - +1.66ms
-

usedJSHeapSize

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main6.10ms - 6.10ms-slower ❌
1% - 1%
0.05ms - 0.05ms
unsure 🔍
+0% - +0%
+0.03ms - +0.03ms
preact-local6.05ms - 6.05msfaster ✔
1% - 1%
0.05ms - 0.05ms
-unsure 🔍
-0% - -0%
-0.03ms - -0.02ms
preact-hooks6.07ms - 6.07msunsure 🔍
-0% - -0%
-0.03ms - -0.03ms
unsure 🔍
+0% - +0%
+0.02ms - +0.03ms
-
many_updates

duration

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main16.54ms - 17.30ms-unsure 🔍
-2% - +4%
-0.26ms - +0.69ms
unsure 🔍
-3% - +4%
-0.55ms - +0.66ms
preact-local16.42ms - 16.99msunsure 🔍
-4% - +2%
-0.69ms - +0.26ms
-unsure 🔍
-4% - +2%
-0.71ms - +0.39ms
preact-hooks16.39ms - 17.33msunsure 🔍
-4% - +3%
-0.66ms - +0.55ms
unsure 🔍
-2% - +4%
-0.39ms - +0.71ms
-

usedJSHeapSize

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main4.52ms - 4.52ms-unsure 🔍
-0% - +0%
-0.00ms - +0.00ms
faster ✔
0% - 1%
0.02ms - 0.02ms
preact-local4.52ms - 4.52msunsure 🔍
-0% - +0%
-0.00ms - +0.00ms
-faster ✔
0% - 1%
0.02ms - 0.02ms
preact-hooks4.54ms - 4.54msslower ❌
0% - 1%
0.02ms - 0.02ms
slower ❌
0% - 1%
0.02ms - 0.02ms
-
text_update

duration

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main2.46ms - 2.54ms-unsure 🔍
-3% - +2%
-0.07ms - +0.04ms
faster ✔
5% - 9%
0.14ms - 0.25ms
preact-local2.47ms - 2.55msunsure 🔍
-2% - +3%
-0.04ms - +0.07ms
-faster ✔
5% - 9%
0.12ms - 0.24ms
preact-hooks2.65ms - 2.73msslower ❌
5% - 10%
0.14ms - 0.25ms
slower ❌
5% - 9%
0.12ms - 0.24ms
-

usedJSHeapSize

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main0.80ms - 0.80ms-unsure 🔍
-0% - +0%
-0.00ms - +0.00ms
faster ✔
3% - 3%
0.02ms - 0.03ms
preact-local0.80ms - 0.80msunsure 🔍
-0% - +0%
-0.00ms - +0.00ms
-faster ✔
3% - 3%
0.02ms - 0.03ms
preact-hooks0.83ms - 0.83msslower ❌
3% - 3%
0.02ms - 0.03ms
slower ❌
3% - 3%
0.02ms - 0.03ms
-
todo

duration

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main27.39ms - 27.76ms-slower ❌
0% - 2%
0.11ms - 0.54ms
faster ✔
2% - 3%
0.50ms - 0.93ms
preact-local27.15ms - 27.36msfaster ✔
0% - 2%
0.11ms - 0.54ms
-faster ✔
3% - 4%
0.88ms - 1.19ms
preact-hooks28.18ms - 28.40msslower ❌
2% - 3%
0.50ms - 0.93ms
slower ❌
3% - 4%
0.88ms - 1.19ms
-

usedJSHeapSize

VersionAvg timevs preact-mainvs preact-localvs preact-hooks
preact-main0.88ms - 0.88ms-unsure 🔍
-0% - +0%
-0.00ms - +0.00ms
faster ✔
3% - 3%
0.03ms - 0.03ms
preact-local0.88ms - 0.88msunsure 🔍
-0% - +0%
-0.00ms - +0.00ms
-faster ✔
3% - 3%
0.03ms - 0.03ms
preact-hooks0.91ms - 0.91msslower ❌
3% - 3%
0.03ms - 0.03ms
slower ❌
3% - 3%
0.03ms - 0.03ms
-

tachometer-reporter-action v2 for Benchmarks

@coveralls
Copy link

coveralls commented Mar 23, 2024

Coverage Status

coverage: 99.469% (-0.1%) from 99.601%
when pulling 0a2ae29 on jviide:event-clock
into bc7c551 on preactjs:main.

Copy link
Member

@JoviDeCroock JoviDeCroock left a comment

Choose a reason for hiding this comment

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

@JoviDeCroock JoviDeCroock merged commit b1d1b87 into preactjs:main Mar 23, 2024
12 of 13 checks passed
@JoviDeCroock JoviDeCroock mentioned this pull request Apr 9, 2024
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.

Event bubbling can break in test conditions
3 participants