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 skewedIndex becoming outrageously big and document tradeoffs of our decisions #4483

Merged
merged 1 commit into from
Aug 28, 2024

Conversation

JoviDeCroock
Copy link
Member

@JoviDeCroock JoviDeCroock commented Aug 27, 2024

Fixes #4482

When we move elements around i.e. [0, 1, 2] --> [1, 0, 2]

--> we diff 1, we find it at position 1 while our skewed index is 0 and our skew is 0
    we set the skew to 1 as we found an offset.
--> we diff 0, we find it at position 0 while our skewed index is at 2 and our skew is 1
    this makes us increase the skew again.
--> we diff 2, we find it at position 2 while our skewed index is at 4 and our skew is 2

This becomes an optimization question where currently we see a 1 element offset as an insertion or deletion i.e. we optimize for [0, 1, 2] --> [9, 0, 1, 2]
while a more than 1 offset we see as a swap.
We could probably build heuristics for having an optimized course of action here as well, but
might go at the cost of some bytes.

If we wanted to optimize for i.e. only swaps we'd just do the last two code-branches and have
only the first item be a re-scouting and all the others fall in their skewed counter-part.
We could also further optimize for swaps.

There are possible tweaks in how we mark a node for insertion, however I don't think it's in scope for this PR and prefer addressing the performance downgrade. Heck we could even remove the optimization for inserts/deletions and save 20-30 more bytes by only relying on >|<.

A more elaborate exampleBasically for the case of:

const a = ['a', 'b', 'c', 'd', 'e'];
const b = ['a', 'd', 'b', 'c', 'e'];

When we follow the new-old algorithm we have now, we know that

  • a is at the same position, no operation required
  • d is moved from position 3 to position 1
    • This makes our skew go to -1 because everything that was before d moves to the left
  • b is moved from position 1 to 2
    • Skew -1, no action
  • c is moved from position 2 to 3
    • Skew -1, no action
  • e has stayed static at position 4
    • Skew -1, but we correct after the fact by seeing that we have an offset of 1

This is no bug because the placeChild algorithm but feels like we could do a lot better in this algorithm by seeing that the length has stayed the same and comparing old to new instead 😅

Ideally we reset the skew again after diffing c

Copy link

github-actions bot commented Aug 27, 2024

📊 Tachometer Benchmark Results

Summary

duration

  • create10k: unsure 🔍 -1% - +1% (-6.95ms - +10.94ms)
    preact-local vs preact-main
  • filter-list: unsure 🔍 -1% - +1% (-0.12ms - +0.19ms)
    preact-local vs preact-main
  • hydrate1k: unsure 🔍 -2% - +1% (-2.01ms - +0.95ms)
    preact-local vs preact-main
  • many-updates: unsure 🔍 -2% - +1% (-0.36ms - +0.12ms)
    preact-local vs preact-main
  • replace1k: unsure 🔍 -2% - +3% (-1.24ms - +2.58ms)
    preact-local vs preact-main
  • text-update: unsure 🔍 -5% - +1% (-0.10ms - +0.02ms)
    preact-local vs preact-main
  • todo: unsure 🔍 -4% - +1% (-1.23ms - +0.26ms)
    preact-local vs preact-main
  • update10th1k: unsure 🔍 -2% - +4% (-0.50ms - +1.26ms)
    preact-local vs preact-main

usedJSHeapSize

  • create10k: unsure 🔍 -0% - +0% (-0.02ms - +0.01ms)
    preact-local vs preact-main
  • filter-list: slower ❌ 0% - 1% (0.00ms - 0.01ms)
    preact-local vs preact-main
  • hydrate1k: unsure 🔍 -1% - +1% (-0.21ms - +0.12ms)
    preact-local vs preact-main
  • many-updates: unsure 🔍 -0% - +0% (-0.00ms - +0.00ms)
    preact-local vs preact-main
  • replace1k: unsure 🔍 -0% - +1% (-0.01ms - +0.03ms)
    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.01ms)
    preact-local vs preact-main

Results

create10k

duration

VersionAvg timevs preact-localvs preact-main
preact-local872.95ms - 889.19ms-unsure 🔍
-1% - +1%
-6.95ms - +10.94ms
preact-main875.33ms - 882.82msunsure 🔍
-1% - +1%
-10.94ms - +6.95ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local25.29ms - 25.32ms-unsure 🔍
-0% - +0%
-0.02ms - +0.01ms
preact-main25.30ms - 25.32msunsure 🔍
-0% - +0%
-0.01ms - +0.02ms
-
filter-list

duration

VersionAvg timevs preact-localvs preact-main
preact-local16.56ms - 16.85ms-unsure 🔍
-1% - +1%
-0.12ms - +0.19ms
preact-main16.61ms - 16.74msunsure 🔍
-1% - +1%
-0.19ms - +0.12ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local1.70ms - 1.70ms-slower ❌
0% - 1%
0.00ms - 0.01ms
preact-main1.69ms - 1.70msfaster ✔
0% - 1%
0.00ms - 0.01ms
-
hydrate1k

duration

VersionAvg timevs preact-localvs preact-main
preact-local79.50ms - 81.15ms-unsure 🔍
-2% - +1%
-2.01ms - +0.95ms
preact-main79.63ms - 82.08msunsure 🔍
-1% - +3%
-0.95ms - +2.01ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local15.65ms - 15.84ms-unsure 🔍
-1% - +1%
-0.21ms - +0.12ms
preact-main15.66ms - 15.93msunsure 🔍
-1% - +1%
-0.12ms - +0.21ms
-
many-updates

duration

VersionAvg timevs preact-localvs preact-main
preact-local16.42ms - 16.78ms-unsure 🔍
-2% - +1%
-0.36ms - +0.12ms
preact-main16.57ms - 16.89msunsure 🔍
-1% - +2%
-0.12ms - +0.36ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local4.61ms - 4.61ms-unsure 🔍
-0% - +0%
-0.00ms - +0.00ms
preact-main4.61ms - 4.62msunsure 🔍
-0% - +0%
-0.00ms - +0.00ms
-
replace1k

duration

VersionAvg timevs preact-localvs preact-main
preact-local75.32ms - 78.08ms-unsure 🔍
-2% - +3%
-1.24ms - +2.58ms
preact-main74.71ms - 77.34msunsure 🔍
-3% - +2%
-2.58ms - +1.24ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local3.50ms - 3.52ms-unsure 🔍
-0% - +1%
-0.01ms - +0.03ms
preact-main3.48ms - 3.51msunsure 🔍
-1% - +0%
-0.03ms - +0.01ms
-

run-warmup-0

VersionAvg timevs preact-localvs preact-main
preact-local28.76ms - 29.31ms-unsure 🔍
-2% - +1%
-0.69ms - +0.20ms
preact-main28.92ms - 29.63msunsure 🔍
-1% - +2%
-0.20ms - +0.69ms
-

run-warmup-1

VersionAvg timevs preact-localvs preact-main
preact-local33.50ms - 35.00ms-unsure 🔍
-4% - +2%
-1.32ms - +0.79ms
preact-main33.77ms - 35.26msunsure 🔍
-2% - +4%
-0.79ms - +1.32ms
-

run-warmup-2

VersionAvg timevs preact-localvs preact-main
preact-local25.81ms - 26.55ms-unsure 🔍
-1% - +2%
-0.30ms - +0.61ms
preact-main25.77ms - 26.28msunsure 🔍
-2% - +1%
-0.61ms - +0.30ms
-

run-warmup-3

VersionAvg timevs preact-localvs preact-main
preact-local29.22ms - 30.89ms-unsure 🔍
-5% - +3%
-1.40ms - +0.89ms
preact-main29.53ms - 31.09msunsure 🔍
-3% - +5%
-0.89ms - +1.40ms
-

run-warmup-4

VersionAvg timevs preact-localvs preact-main
preact-local22.54ms - 23.91ms-unsure 🔍
-5% - +4%
-1.20ms - +0.93ms
preact-main22.54ms - 24.18msunsure 🔍
-4% - +5%
-0.93ms - +1.20ms
-

run-final

VersionAvg timevs preact-localvs preact-main
preact-local23.18ms - 24.28ms-unsure 🔍
-3% - +3%
-0.74ms - +0.80ms
preact-main23.16ms - 24.24msunsure 🔍
-3% - +3%
-0.80ms - +0.74ms
-
text-update

duration

VersionAvg timevs preact-localvs preact-main
preact-local1.92ms - 2.01ms-unsure 🔍
-5% - +1%
-0.10ms - +0.02ms
preact-main1.96ms - 2.05msunsure 🔍
-1% - +5%
-0.02ms - +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-local27.31ms - 27.52ms-unsure 🔍
-4% - +1%
-1.23ms - +0.26ms
preact-main27.16ms - 28.64msunsure 🔍
-1% - +4%
-0.26ms - +1.23ms
-

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-local30.36ms - 31.69ms-unsure 🔍
-2% - +4%
-0.50ms - +1.26ms
preact-main30.07ms - 31.22msunsure 🔍
-4% - +2%
-1.26ms - +0.50ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local3.56ms - 3.57ms-unsure 🔍
-0% - +0%
-0.00ms - +0.01ms
preact-main3.56ms - 3.57msunsure 🔍
-0% - +0%
-0.01ms - +0.00ms
-

tachometer-reporter-action v2 for Benchmarks

Copy link

github-actions bot commented Aug 27, 2024

Size Change: -118 B (-0.19%)

Total Size: 62 kB

Filename Size Change
dist/preact.js 4.7 kB -19 B (-0.4%)
dist/preact.min.js 4.73 kB -20 B (-0.42%)
dist/preact.min.module.js 4.73 kB -20 B (-0.42%)
dist/preact.min.umd.js 4.76 kB -19 B (-0.4%)
dist/preact.module.js 4.72 kB -21 B (-0.44%)
dist/preact.umd.js 4.78 kB -19 B (-0.4%)
ℹ️ View Unchanged
Filename Size
compat/dist/compat.js 4.11 kB
compat/dist/compat.module.js 4.04 kB
compat/dist/compat.umd.js 4.18 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 274 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

coveralls commented Aug 27, 2024

Coverage Status

coverage: 99.486%. remained the same
when pulling a6c3cff on fixes-to-diffing
into 8e8dd92 on main.

@JoviDeCroock JoviDeCroock changed the title Fix skewedIndex becoming outrageously sized and document tradeoffs of our decisions Fix skewedIndex becoming outrageously big and document tradeoffs of our decisions Aug 27, 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.

Performance issue in findMatchingIndex after upgrade to 10.23.2
3 participants