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

Slider Control: Fixing the lag #6063

Merged
merged 2 commits into from
Jul 11, 2024
Merged

Conversation

balazsbajorics
Copy link
Contributor

@balazsbajorics balazsbajorics commented Jul 11, 2024

Problem:
For projects with really bad performance, the slider control would oddly lag behind the canvas and the number control.
Before
Note how the slider control doesn't update while the number control and the canvas do update

Diagnosis:
The slider control uses a local state to store the drag's current value. Probably because our dispatch internally uses a flushSync, this local state update was treated with a lower priority in React, and because the frame times are egregious, it never got enough idle time for a requestIdleCallback.

Fix:
After
note how the slider updates the same time as the number control and the canvas

By wrapping the local state update into a flushSync block, I managed to force it to update with the same priority as the rest of the editor.
Note: The frame times are still egregious, but that's a different problem.

Fixes #6009

Copy link
Contributor

github-actions bot commented Jul 11, 2024

Try me

Copy link

relativeci bot commented Jul 11, 2024

#13338 Bundle Size — 62.66MiB (~+0.01%).

140c7b8(current) vs 6339ece master#13335(baseline)

Warning

Bundle contains 70 duplicate packages – View duplicate packages

Bundle metrics  Change 2 changes Regression 1 regression
                 Current
#13338
     Baseline
#13335
Regression  Initial JS 45.71MiB(~+0.01%) 45.71MiB
No change  Initial CSS 0B 0B
Change  Cache Invalidation 22.28% 24.14%
No change  Chunks 30 30
No change  Assets 33 33
No change  Modules 4374 4374
No change  Duplicate Modules 524 524
No change  Duplicate Code 31.7% 31.7%
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
#13338
     Baseline
#13335
Regression  JS 62.64MiB (~+0.01%) 62.64MiB
Improvement  HTML 11.16KiB (-0.33%) 11.2KiB

Bundle analysis reportBranch fix/slider-control-lagProject dashboard

@balazsbajorics balazsbajorics merged commit 0023156 into master Jul 11, 2024
18 checks passed
@balazsbajorics balazsbajorics deleted the fix/slider-control-lag branch July 11, 2024 13:45
liady pushed a commit that referenced this pull request Dec 13, 2024
**Problem:**
For projects with really bad performance, the slider control would oddly
lag behind the canvas and the number control.

![Before](https://github.com/concrete-utopia/utopia/assets/2226774/b2569e46-1712-4b86-b35a-f96a3fd54f18)
_Note how the slider control doesn't update while the number control and
the canvas do update_

**Diagnosis:**
The slider control uses a local state to store the drag's current value.
Probably because our dispatch internally uses a flushSync, this local
state update was treated with a lower priority in React, and because the
frame times are egregious, it never got enough idle time for a
requestIdleCallback.

**Fix:**

![After](https://github.com/concrete-utopia/utopia/assets/2226774/55bc2a27-b311-4d76-90bf-0caa0110ec25)
_note how the slider updates the same time as the number control and the
canvas_

By wrapping the local state update into a flushSync block, I managed to
force it to update with the same priority as the rest of the editor.
**Note:** The frame times are still egregious, but that's a different
problem.

Fixes #6009
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants