-
Notifications
You must be signed in to change notification settings - Fork 171
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
Don't render when code ahead #6069
Conversation
#13351 Bundle Size — 62.64MiB (-0.02%).
Warning Bundle contains 70 duplicate packages – View duplicate packages Bundle metrics
|
Current #13351 |
Baseline #13350 |
|
---|---|---|
Initial JS | 45.71MiB (~+0.01% ) |
45.71MiB |
Initial CSS | 0B |
0B |
Cache Invalidation | 19.24% |
21.6% |
Chunks | 31 (+3.33% ) |
30 |
Assets | 34 (+3.03% ) |
33 |
Modules | 4371 (-0.07% ) |
4374 |
Duplicate Modules | 521 (-0.57% ) |
524 |
Duplicate Code | 31.68% (-0.06% ) |
31.7% |
Packages | 469 |
469 |
Duplicate Packages | 70 |
70 |
Bundle size by type 2 changes
2 improvements
Current #13351 |
Baseline #13350 |
|
---|---|---|
JS | 62.63MiB (-0.02% ) |
62.65MiB |
HTML | 11.16KiB (-0.33% ) |
11.2KiB |
Bundle analysis report Branch fix/dont-render-when-code-ahead Project dashboard
@@ -450,7 +451,12 @@ export class Editor { | |||
const reactRouterErrorPreviouslyLogged = hasReactRouterErrorBeenLogged() | |||
|
|||
const runDomWalker = shouldRunDOMWalker(dispatchedActions, dispatchResult) | |||
const shouldRerender = !dispatchResult.nothingChanged || runDomWalker |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that shouldRerender
was actually very badly named here, and so changed some of the gating of the code below accordingly. It's worth expanding the diff below to understand what is actually happening now
@@ -467,89 +473,90 @@ export class Editor { | |||
}) | |||
}) | |||
}) | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:narrows_eyes: the original code assumes that it only makes sense to run the dom-walker if there was a canvas render. is that assumption false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldRerender
was a bit of a misnomer, especially as it was gating logic that should run regardless of if that canvas rendered (e.g. the editorDispatchClosingOut
at the end). There are cases where it makes sense to run the dom-walker without a canvas render (e.g. navigating to a different route). But that being said, the below condition should actually be somethingChanged || runDomWalker
so I'll fix that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated it to shouldRerender || runDomWalker
in the end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm, but shouldRerender is already const shouldRerender = (somethingChanged || runDomWalker) && !anyCodeAhead(dispatchResult.unpatchedEditor.projectContents)
, aren't you defeating the anyCodeAhead check then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dom walker should run whenever the canvas is rendered, hence the shouldRerender
check, but it should also run when we explicitly ask it to (e.g. when the editor is in play mode and the user has navigated to a different route), hence the || runDomWalker
.
…-utopia/utopia into fix/dont-render-when-code-ahead
**Problem:** When making code changes, we'll cause the canvas to re-render twice: once when the code is changed; and then a second time once the parsed model has caught up. **Fix:** Specifically check if any code is ahead before triggering a canvas render. To do this I used the existing `shouldRerender` in `editor.tsx`, but realised that was actually a bit of a misnomer, and was gating logic that it shouldn't be. So I have explicitly used the relevant boolean checks around the individual parts of the code called after a dispatch. Note that I have completely removed the check around `editorDispatchClosingOut`. I'm very much certain that we should never have been gating that with a check that something had changed, as the internal logic of that function is already checking that something actually changed before e.g. triggering a save. My only concern with this was that if you are typing fast enough it would prevent the canvas from rendering until you paused briefly, because we don't change the revisions state following a parser-printer update if the update is stale here: <https://github.com/concrete-utopia/utopia/blob/67abcdd1d9fa11c0bf42be255cf655bba45a5a38/editor/src/core/shared/parser-projectcontents-utils.ts#L100-L109> However, in practice, even on the hydrogen project this never happened, because the IndexedDB polling part which forms the code-editor-to-utopia communication channel is slower than parsing the code. So I then added a 600ms pause in the parsing to force the code updates to come through faster, which meant updating the canvas only happened when you stopped typing, and even in that forced case it actually didn't feel bad. **Manual Tests:** I hereby swear that: - [x] I opened a hydrogen project and it loaded - [x] I could navigate to various routes in Preview mode --------- Co-authored-by: Sean Parsons <[email protected]>
Problem:
When making code changes, we'll cause the canvas to re-render twice: once when the code is changed; and then a second time once the parsed model has caught up.
Fix:
Specifically check if any code is ahead before triggering a canvas render. To do this I used the existing
shouldRerender
ineditor.tsx
, but realised that was actually a bit of a misnomer, and was gating logic that it shouldn't be. So I have explicitly used the relevant boolean checks around the individual parts of the code called after a dispatch.Note that I have completely removed the check around
editorDispatchClosingOut
. I'm very much certain that we should never have been gating that with a check that something had changed, as the internal logic of that function is already checking that something actually changed before e.g. triggering a save.My only concern with this was that if you are typing fast enough it would prevent the canvas from rendering until you paused briefly, because we don't change the revisions state following a parser-printer update if the update is stale here:
utopia/editor/src/core/shared/parser-projectcontents-utils.ts
Lines 100 to 109 in 67abcdd
However, in practice, even on the hydrogen project this never happened, because the IndexedDB polling part which forms the code-editor-to-utopia communication channel is slower than parsing the code. So I then added a 600ms pause in the parsing to force the code updates to come through faster, which meant updating the canvas only happened when you stopped typing, and even in that forced case it actually didn't feel bad.
Manual Tests:
I hereby swear that: