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

feat: support ref cleanup functions #4436

Merged
merged 2 commits into from
Jul 7, 2024
Merged

feat: support ref cleanup functions #4436

merged 2 commits into from
Jul 7, 2024

Conversation

marvinhagemeister
Copy link
Member

Fixes #4435

Copy link

github-actions bot commented Jul 6, 2024

📊 Tachometer Benchmark Results

Summary

duration

  • create10k: unsure 🔍 -1% - +2% (-7.91ms - +14.32ms)
    preact-local vs preact-main
  • filter-list: unsure 🔍 -3% - +2% (-0.45ms - +0.37ms)
    preact-local vs preact-main
  • hydrate1k: unsure 🔍 -3% - +1% (-1.88ms - +0.82ms)
    preact-local vs preact-main
  • many-updates: unsure 🔍 -2% - +2% (-0.34ms - +0.29ms)
    preact-local vs preact-main
  • replace1k: unsure 🔍 -1% - +3% (-1.15ms - +2.44ms)
    preact-local vs preact-main
  • text-update: unsure 🔍 -5% - +5% (-0.10ms - +0.10ms)
    preact-local vs preact-main
  • todo: unsure 🔍 -2% - +0% (-0.54ms - +0.01ms)
    preact-local vs preact-main
  • update10th1k: unsure 🔍 -1% - +2% (-0.27ms - +0.47ms)
    preact-local vs preact-main

usedJSHeapSize

  • create10k: unsure 🔍 +0% - +0% (+0.00ms - +0.00ms)
    preact-local vs preact-main
  • filter-list: unsure 🔍 -0% - +0% (-0.00ms - +0.00ms)
    preact-local vs preact-main
  • hydrate1k: unsure 🔍 -2% - +1% (-0.33ms - +0.14ms)
    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.02ms)
    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
  • update10th1k: unsure 🔍 +0% - +0% (+0.00ms - +0.00ms)
    preact-local vs preact-main

Results

create10k

duration

VersionAvg timevs preact-localvs preact-main
preact-local878.32ms - 894.04ms-unsure 🔍
-1% - +2%
-7.91ms - +14.32ms
preact-main875.12ms - 890.84msunsure 🔍
-2% - +1%
-14.32ms - +7.91ms
-

usedJSHeapSize

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

duration

VersionAvg timevs preact-localvs preact-main
preact-local16.62ms - 17.20ms-unsure 🔍
-3% - +2%
-0.45ms - +0.37ms
preact-main16.65ms - 17.24msunsure 🔍
-2% - +3%
-0.37ms - +0.45ms
-

usedJSHeapSize

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

duration

VersionAvg timevs preact-localvs preact-main
preact-local68.29ms - 69.09ms-unsure 🔍
-3% - +1%
-1.88ms - +0.82ms
preact-main67.93ms - 70.51msunsure 🔍
-1% - +3%
-0.82ms - +1.88ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local13.05ms - 13.38ms-unsure 🔍
-2% - +1%
-0.33ms - +0.14ms
preact-main13.15ms - 13.47msunsure 🔍
-1% - +3%
-0.14ms - +0.33ms
-
many-updates

duration

VersionAvg timevs preact-localvs preact-main
preact-local16.34ms - 16.86ms-unsure 🔍
-2% - +2%
-0.34ms - +0.29ms
preact-main16.44ms - 16.81msunsure 🔍
-2% - +2%
-0.29ms - +0.34ms
-

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-local77.18ms - 79.76ms-unsure 🔍
-1% - +3%
-1.15ms - +2.44ms
preact-main76.58ms - 79.07msunsure 🔍
-3% - +1%
-2.44ms - +1.15ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local3.52ms - 3.55ms-unsure 🔍
-1% - +0%
-0.03ms - +0.02ms
preact-main3.53ms - 3.56msunsure 🔍
-0% - +1%
-0.02ms - +0.03ms
-

run-warmup-0

VersionAvg timevs preact-localvs preact-main
preact-local29.07ms - 29.71ms-unsure 🔍
-2% - +1%
-0.47ms - +0.43ms
preact-main29.10ms - 29.73msunsure 🔍
-1% - +2%
-0.43ms - +0.47ms
-

run-warmup-1

VersionAvg timevs preact-localvs preact-main
preact-local34.82ms - 36.70ms-unsure 🔍
-1% - +7%
-0.24ms - +2.48ms
preact-main33.66ms - 35.63msunsure 🔍
-7% - +1%
-2.48ms - +0.24ms
-

run-warmup-2

VersionAvg timevs preact-localvs preact-main
preact-local25.72ms - 26.08ms-unsure 🔍
-2% - +1%
-0.56ms - +0.16ms
preact-main25.80ms - 26.41msunsure 🔍
-1% - +2%
-0.16ms - +0.56ms
-

run-warmup-3

VersionAvg timevs preact-localvs preact-main
preact-local31.10ms - 32.58ms-unsure 🔍
-1% - +5%
-0.44ms - +1.59ms
preact-main30.57ms - 31.96msunsure 🔍
-5% - +1%
-1.59ms - +0.44ms
-

run-warmup-4

VersionAvg timevs preact-localvs preact-main
preact-local22.04ms - 23.57ms-unsure 🔍
-6% - +3%
-1.46ms - +0.67ms
preact-main22.45ms - 23.94msunsure 🔍
-3% - +6%
-0.67ms - +1.46ms
-

run-final

VersionAvg timevs preact-localvs preact-main
preact-local23.61ms - 24.71ms-unsure 🔍
-1% - +6%
-0.12ms - +1.32ms
preact-main23.10ms - 24.02msunsure 🔍
-5% - +0%
-1.32ms - +0.12ms
-
text-update

duration

VersionAvg timevs preact-localvs preact-main
preact-local1.90ms - 2.03ms-unsure 🔍
-5% - +5%
-0.10ms - +0.10ms
preact-main1.90ms - 2.03msunsure 🔍
-5% - +5%
-0.10ms - +0.10ms
-

usedJSHeapSize

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

duration

VersionAvg timevs preact-localvs preact-main
preact-local26.03ms - 26.21ms-unsure 🔍
-2% - +0%
-0.54ms - +0.01ms
preact-main26.12ms - 26.65msunsure 🔍
-0% - +2%
-0.01ms - +0.54ms
-

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-local29.17ms - 29.83ms-unsure 🔍
-1% - +2%
-0.27ms - +0.47ms
preact-main29.24ms - 29.56msunsure 🔍
-2% - +1%
-0.47ms - +0.27ms
-

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

Copy link

github-actions bot commented Jul 6, 2024

Size Change: +145 B (+0.23%)

Total Size: 61.9 kB

Filename Size Change
dist/preact.js 4.7 kB +23 B (+0.49%)
dist/preact.min.js 4.74 kB +25 B (+0.53%)
dist/preact.min.module.js 4.73 kB +24 B (+0.51%)
dist/preact.min.umd.js 4.76 kB +24 B (+0.51%)
dist/preact.module.js 4.73 kB +22 B (+0.47%)
dist/preact.umd.js 4.78 kB +27 B (+0.57%)
ℹ️ 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
hooks/dist/hooks.js 1.53 kB
hooks/dist/hooks.module.js 1.56 kB
hooks/dist/hooks.umd.js 1.6 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

@coveralls
Copy link

Coverage Status

coverage: 99.612% (+0.002%) from 99.61%
when pulling 7bb245a on ref-cleanup
into db0f4f2 on main.

@coveralls
Copy link

Coverage Status

coverage: 99.612% (+0.002%) from 99.61%
when pulling 7bb245a on ref-cleanup
into db0f4f2 on main.

ref._unmount();
}

if (!hasRefUnmount || value != null) {
Copy link
Member

@JoviDeCroock JoviDeCroock Jul 7, 2024

Choose a reason for hiding this comment

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

Why do we need !hasRefUnmount here? Wouldn't it be safe to always invoke this and inline typeof ref._unmount == 'function' above?

EDIT: seems needed when I tested it out

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe inverting the check makes it more clear. When a cleanup function is returned, then the ref function should never be invoked with null. But when no cleanup function is there it should be invoked with null.

if (typeof ref == 'function') ref(value);
else ref.current = value;
if (typeof ref == 'function') {
let hasRefUnmount = typeof ref._unmount == 'function';
Copy link
Member

Choose a reason for hiding this comment

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

We'll need to add _unmount to mangle to be safe I reckon

Copy link
Member Author

Choose a reason for hiding this comment

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

It's already there as we use that for options._unmount too.

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.

Looks great!

@marvinhagemeister marvinhagemeister merged commit 212b1f6 into main Jul 7, 2024
13 checks passed
@marvinhagemeister marvinhagemeister deleted the ref-cleanup branch July 7, 2024 12:34
@JoviDeCroock JoviDeCroock mentioned this pull request Jul 20, 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.

Support cleanup functions for refs
3 participants