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

Improve performance of vnodeId generation #2978

Merged
merged 2 commits into from
May 10, 2021
Merged

Conversation

developit
Copy link
Member

@developit developit commented Feb 6, 2021

This PR removes the need for an options._vnodeId shared counter by creating separate "keyspaces" within vnodeId (vnode._original) using signed integers. Despite not sharing the ID counter, h() allocates positive monotonic ID's and jsx() negative IDs, which prevents collisions. It also doubles the number of available ID values. The performance improvement here is a result of avoiding a property get + set on every VNode, not sure if that will come through in the benchmarks since we already do a loop and set many properties on props.

Another option that might be worth testing would be to keep IDs unsigned by having jsx() generate IDs starting at 9e9. This would create a collision scenario if h() were to create 9 billion VNodes.

@github-actions
Copy link

github-actions bot commented Feb 6, 2021

📊 Tachometer Benchmark Results

Summary

duration

  • 02_replace1k: unsure 🔍 -5% - +14% (-7.02ms - +19.12ms)
    preact-local vs preact-master
  • 03_update10th1k_x16: unsure 🔍 -5% - +2% (-1.74ms - +0.65ms)
    preact-local vs preact-master
  • 07_create10k: unsure 🔍 -1% - +1% (-11.90ms - +9.02ms)
    preact-local vs preact-master
  • filter_list: unsure 🔍 -4% - +3% (-1.22ms - +0.91ms)
    preact-local vs preact-master
  • hydrate1k: faster ✔ 0% - 4% (0.18ms - 5.15ms)
    preact-local vs preact-master
  • many_updates: unsure 🔍 -13% - +6% (-4.18ms - +2.14ms)
    preact-local vs preact-master
  • text_update: unsure 🔍 -4% - +4% (-0.17ms - +0.15ms)
    preact-local vs preact-master

usedJSHeapSize

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

Results

02_replace1k

duration

VersionAvg timevs preact-mastervs preact-local
preact-master131.82ms - 147.00ms-unsure 🔍
-13% - +5%
-19.12ms - +7.02ms
preact-local134.83ms - 156.10msunsure 🔍
-5% - +14%
-7.02ms - +19.12ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-local
preact-master3.59ms - 3.61ms-unsure 🔍
-0% - +0%
-0.01ms - +0.02ms
preact-local3.59ms - 3.61msunsure 🔍
-0% - +0%
-0.02ms - +0.01ms
-

run-warmup-0

VersionAvg timevs preact-mastervs preact-local
preact-master55.94ms - 64.15ms-unsure 🔍
-7% - +12%
-4.24ms - +6.84ms
preact-local55.02ms - 62.46msunsure 🔍
-11% - +7%
-6.84ms - +4.24ms
-

run-warmup-1

VersionAvg timevs preact-mastervs preact-local
preact-master86.81ms - 98.33ms-unsure 🔍
-10% - +9%
-9.48ms - +8.22ms
preact-local86.48ms - 99.92msunsure 🔍
-9% - +10%
-8.22ms - +9.48ms
-

run-warmup-2

VersionAvg timevs preact-mastervs preact-local
preact-master93.83ms - 109.50ms-unsure 🔍
-11% - +11%
-10.88ms - +11.20ms
preact-local93.73ms - 109.29msunsure 🔍
-11% - +11%
-11.20ms - +10.88ms
-

run-warmup-3

VersionAvg timevs preact-mastervs preact-local
preact-master53.24ms - 61.64ms-unsure 🔍
-14% - +8%
-8.24ms - +5.10ms
preact-local53.83ms - 64.20msunsure 🔍
-9% - +14%
-5.10ms - +8.24ms
-

run-warmup-4

VersionAvg timevs preact-mastervs preact-local
preact-master93.39ms - 111.90ms-unsure 🔍
-4% - +21%
-3.54ms - +19.46ms
preact-local87.86ms - 101.50msunsure 🔍
-18% - +3%
-19.46ms - +3.54ms
-

run-final

VersionAvg timevs preact-mastervs preact-local
preact-master51.10ms - 56.64ms-unsure 🔍
-13% - +4%
-7.34ms - +2.40ms
preact-local52.33ms - 60.35msunsure 🔍
-5% - +14%
-2.40ms - +7.34ms
-
03_update10th1k_x16

duration

VersionAvg timevs preact-mastervs preact-local
preact-master34.95ms - 36.66ms-unsure 🔍
-2% - +5%
-0.65ms - +1.74ms
preact-local34.42ms - 36.10msunsure 🔍
-5% - +2%
-1.74ms - +0.65ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-local
preact-master3.65ms - 3.66ms-unsure 🔍
-0% - +0%
-0.01ms - +0.01ms
preact-local3.66ms - 3.66msunsure 🔍
-0% - +0%
-0.01ms - +0.01ms
-
07_create10k

duration

VersionAvg timevs preact-mastervs preact-local
preact-master1314.35ms - 1328.09ms-unsure 🔍
-1% - +1%
-9.02ms - +11.90ms
preact-local1311.90ms - 1327.67msunsure 🔍
-1% - +1%
-11.90ms - +9.02ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-local
preact-master25.98ms - 25.98ms-unsure 🔍
-0% - +0%
-0.00ms - +0.00ms
preact-local25.98ms - 25.98msunsure 🔍
-0% - +0%
-0.00ms - +0.00ms
-
filter_list

duration

VersionAvg timevs preact-mastervs preact-local
preact-master27.12ms - 28.75ms-unsure 🔍
-3% - +4%
-0.91ms - +1.22ms
preact-local27.09ms - 28.47msunsure 🔍
-4% - +3%
-1.22ms - +0.91ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-local
preact-master1.64ms - 1.68ms-unsure 🔍
-2% - +1%
-0.03ms - +0.02ms
preact-local1.64ms - 1.68msunsure 🔍
-1% - +2%
-0.02ms - +0.03ms
-
hydrate1k

duration

VersionAvg timevs preact-mastervs preact-local
preact-master115.46ms - 118.75ms-slower ❌
0% - 5%
0.18ms - 5.15ms
preact-local112.58ms - 116.31msfaster ✔
0% - 4%
0.18ms - 5.15ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-local
preact-master6.33ms - 6.36ms-unsure 🔍
-0% - +0%
-0.01ms - +0.02ms
preact-local6.33ms - 6.35msunsure 🔍
-0% - +0%
-0.02ms - +0.01ms
-
many_updates

duration

VersionAvg timevs preact-mastervs preact-local
preact-master29.41ms - 34.55ms-unsure 🔍
-7% - +14%
-2.14ms - +4.18ms
preact-local29.12ms - 32.80msunsure 🔍
-13% - +6%
-4.18ms - +2.14ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-local
preact-master4.84ms - 4.87ms-unsure 🔍
-0% - +0%
-0.02ms - +0.01ms
preact-local4.85ms - 4.87msunsure 🔍
-0% - +0%
-0.01ms - +0.02ms
-
text_update

duration

VersionAvg timevs preact-mastervs preact-local
preact-master3.66ms - 3.92ms-unsure 🔍
-4% - +4%
-0.15ms - +0.17ms
preact-local3.69ms - 3.87msunsure 🔍
-4% - +4%
-0.17ms - +0.15ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-local
preact-master0.83ms - 0.83ms-unsure 🔍
+0% - +0%
+0.00ms - +0.00ms
preact-local0.83ms - 0.83msunsure 🔍
-0% - -0%
-0.00ms - -0.00ms
-

tachometer-reporter-action v2 for Benchmarks

@coveralls
Copy link

coveralls commented Feb 6, 2021

Coverage Status

Coverage increased (+0.0007%) to 99.626% when pulling 477ab13 on perf-vnodeid into 84b1331 on master.

@github-actions
Copy link

github-actions bot commented Feb 6, 2021

Size Change: -25 B (0%)

Total Size: 42 kB

Filename Size Change
dist/preact.js 3.98 kB +12 B (0%)
dist/preact.min.js 4 kB -5 B (0%)
dist/preact.module.js 4 kB -1 B
dist/preact.umd.js 4.04 kB -3 B (0%)
jsx-runtime/dist/jsxRuntime.js 317 B -10 B (3%)
jsx-runtime/dist/jsxRuntime.module.js 327 B -8 B (2%)
jsx-runtime/dist/jsxRuntime.umd.js 395 B -10 B (2%)
ℹ️ View Unchanged
Filename Size Change
compat/dist/compat.js 3.39 kB 0 B
compat/dist/compat.module.js 3.38 kB 0 B
compat/dist/compat.umd.js 3.44 kB 0 B
debug/dist/debug.js 2.99 kB 0 B
debug/dist/debug.module.js 2.98 kB 0 B
debug/dist/debug.umd.js 3.07 kB 0 B
devtools/dist/devtools.js 232 B 0 B
devtools/dist/devtools.module.js 241 B 0 B
devtools/dist/devtools.umd.js 308 B 0 B
hooks/dist/hooks.js 1.13 kB 0 B
hooks/dist/hooks.module.js 1.15 kB 0 B
hooks/dist/hooks.umd.js 1.2 kB 0 B
test-utils/dist/testUtils.js 437 B 0 B
test-utils/dist/testUtils.module.js 439 B 0 B
test-utils/dist/testUtils.umd.js 515 B 0 B

compressed-size-action

developit added a commit that referenced this pull request Feb 6, 2021
@developit developit mentioned this pull request Feb 6, 2021
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.

Nice one!

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.

4 participants