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/memoized should update #6098

Merged
merged 5 commits into from
Jul 19, 2024
Merged

Conversation

balazsbajorics
Copy link
Contributor

Problem:

image

There's a shouldUpdate function in ComponentRendererComponent which is not cheap, and it is memoized, and it's called 8 times for each canvas update, even for components where shouldUpdate will eventually be false.

Fix:
Turning shouldUpdate into a memoized function, only recalculating the value when any of its inputs change:
image

The time spent goes from ~1.5ms to sub 0.2ms.

This is doubly relevant because I have a follow-up PR which introduces shouldUpdate-style callbacks to even more places.

Copy link
Contributor

github-actions bot commented Jul 18, 2024

Try me

Copy link

relativeci bot commented Jul 18, 2024

#13436 Bundle Size — 62.63MiB (~+0.01%).

f16cef4(current) vs 6339ece master#13428(baseline)

Warning

Bundle contains 70 duplicate packages – View duplicate packages

Bundle metrics  Change 2 changes Regression 1 regression
                 Current
#13436
     Baseline
#13428
Regression  Initial JS 45.7MiB(~+0.01%) 45.7MiB
No change  Initial CSS 0B 0B
Change  Cache Invalidation 21.54% 21.99%
No change  Chunks 31 31
No change  Assets 34 34
No change  Modules 4374 4374
No change  Duplicate Modules 523 523
No change  Duplicate Code 31.69% 31.69%
No change  Packages 469 469
No change  Duplicate Packages 70 70
Bundle size by type  Change 2 changes Regression 1 regression Improvement 1 improvement
                 Current
#13436
     Baseline
#13428
Regression  JS 62.62MiB (~+0.01%) 62.62MiB
Improvement  HTML 11.16KiB (-0.33%) 11.2KiB

Bundle analysis reportBranch fix/memoized-should-updateProject dashboard

@balazsbajorics balazsbajorics merged commit b45b071 into master Jul 19, 2024
13 checks passed
@balazsbajorics balazsbajorics deleted the fix/memoized-should-update branch July 19, 2024 09:55
liady pushed a commit that referenced this pull request Dec 13, 2024
**Problem:**

<img width="1402" alt="image"
src="https://github.com/user-attachments/assets/b83471ac-1eee-4e11-be7f-584c3a441e84">

There's a `shouldUpdate` function in ComponentRendererComponent which is
not cheap, and it is memoized, and it's called 8 times for each canvas
update, even for components where shouldUpdate will eventually be false.

**Fix:**
Turning shouldUpdate into a memoized function, only recalculating the
value when any of its inputs change:
<img width="1044" alt="image"
src="https://github.com/user-attachments/assets/df866148-825f-4ac0-9230-78daa698f7c0">

The time spent goes from ~1.5ms to sub 0.2ms.

This is doubly relevant because I have a follow-up PR which introduces
shouldUpdate-style callbacks to even more places.
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.

5 participants