Skip to content

Albert load workflow opt - #1398

Merged
zuozhiw merged 6 commits into
masterfrom
albert-load_workflow_opt
Feb 4, 2022
Merged

zuozhiw merged 6 commits into
masterfrom
albert-load_workflow_opt

Conversation

@MysteriousChallenger

@MysteriousChallenger MysteriousChallenger commented Jan 14, 2022 •

Copy link
Copy Markdown
Contributor

Some quick fixes to improve page load times for large workflows by ~ 1/2. Specifically reduces time spent rendering the page.

Changes:

  • add Async option to main jointpaper.
    • This enables us to buffer jointjs operations and avoid costly redraws.
    • added context manager interface for automatically freezing and unfreezing jointpaper.
  • Use addCells to add lists of jointjs cells instead of looping over addCell to add one cell at a time

Results:

  • Before:

    • Screenshot_20220121_002925
  • async freeze/unfreeze

    • Screenshot_20220121_003110
  • async + addCells()

    • Screenshot_20220121_003414

...by freezing joint paper until all updates are complete,
skipping unnecesarry rendering
...by batching the addition of new operators
with one addcells() / resetcells() call
@MysteriousChallenger

Copy link
Copy Markdown
Contributor Author

I've had to compromise on some things:

  • async mode is only turned on briefly to perform reloadworkflow().
    using async globally caused too many non-deterministic regression test fails. I couldn't diagnose them, they kept disappearing on me

  • resetCells doesn't trigger the addcell jointgraph event, which texera uses to synchronise its internal graph and the visible graph, causing some bugs aswell

}

return ContextManager;
} No newline at end of file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContextManager is my attempt to bring python's context managers to typescript. It can be used to:

  • bind and release resources reliably
  • act as *global state*, but only controlled from one place in the code. Using withContext, you can execute a function with some context, and any resulting function call in the stack can be aware of that context.

This was originally introduced right before I figured out async mode was a toggle-able option
My idea was to set the paper to async permanently, and create a sync/async boolean context.

for every function that changes the jointpaper, check if they're called in an async context, and if not, manually sync the jointpaper to emulate the behavior of sychronous mode.

@zuozhiw zuozhiw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I made some minor changes and we can merge it.
I tested it on the production server and the loading time of large workflows reduce from ~3 seconds to 1 second on my machine.

@zuozhiw
zuozhiw merged commit 0896e9d into master Feb 4, 2022
@zuozhiw
zuozhiw deleted the albert-load_workflow_opt branch February 4, 2022 06:27
@Xiao-zhen-Liu

Copy link
Copy Markdown
Contributor

I found a bug when merging this part into #1427 and found it exists in master: when reloading a workflow, all the links will appear to have breakpoints (when actually they do not). Hovering on the "!" will make the icon disappear though.
image

@sadeemsaleh

Copy link
Copy Markdown
Contributor

Seems this PR breaks the version preview as it depends on the reloadWorkflow function, which is the major change in this PR

@MysteriousChallenger
MysteriousChallenger restored the albert-load_workflow_opt branch February 6, 2022 09:18
@MysteriousChallenger

MysteriousChallenger commented Feb 6, 2022 •

Copy link
Copy Markdown
Contributor Author

Bug squashed: #1433

I found a bug when merging this part into #1427 and found it exists in master: when reloading a workflow, all the links will appear to have breakpoints (when actually they do not). Hovering on the "!" will make the icon disappear though. image

zuozhiw added a commit that referenced this pull request Feb 7, 2022
# Continuation of #1398

# The bug:

There is an event listener responsible for adding the link breakpoint button to all links:
```
getJointLinkCellAddStream().subscribe(link => {
    const linkView = link.findView(this.getJointPaper());
    ...
    linkView.hideTools(); // hides breakpoint icon
});
```

In async mode, the link cell is added to the graph but not drawn to the webpage (This avoids an expensive DOM reflow)

Since it's not drawn to the webpage, hideTools doesn't work right (for reasons unknown, it fails silently)

# The solution:
We can't draw the link cells: the whole point is to avoid DOM reflows
Instead, we modify the event stream getJointLinkCellAddStream() to buffer its events while the jointgraph is in async mode and emit them all at once afterwards.

I adapted the method from https://kddsky.medium.com/pauseable-observables-in-rxjs-58ce2b8c7dfd (02/06/22)
```
merge(
  source$.pipe( bufferToggle(off$, ()=>on$)  ),
  source$.pipe( windowToggle(on$,  ()=>off$) )
).pipe(
  // then flatten buffer arrays and window Observables
  flatMap(x => x)
)
```
bufferToggle starts buffering on **_off$_**, and emits on **_on$_**
windowToggle starts emitting on **_on$_** and stops emitting on **_off$_**


P.S. 
https://kddsky.medium.com/pauseable-observables-in-rxjs-58ce2b8c7dfd (02/06/22) 
this article had another cool trick for rate-limiting for bursty events

Co-authored-by: zuozhiw <[email protected]>
@Yicong-Huang Yicong-Huang added frontend Changes related to the frontend GUI and removed gui labels Jul 6, 2025
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
yangzhang75 pushed a commit to yangzhang75/texera that referenced this pull request Jun 22, 2026
# Continuation of apache#1398

# The bug:

There is an event listener responsible for adding the link breakpoint button to all links:
```
getJointLinkCellAddStream().subscribe(link => {
    const linkView = link.findView(this.getJointPaper());
    ...
    linkView.hideTools(); // hides breakpoint icon
});
```

In async mode, the link cell is added to the graph but not drawn to the webpage (This avoids an expensive DOM reflow)

Since it's not drawn to the webpage, hideTools doesn't work right (for reasons unknown, it fails silently)

# The solution:
We can't draw the link cells: the whole point is to avoid DOM reflows
Instead, we modify the event stream getJointLinkCellAddStream() to buffer its events while the jointgraph is in async mode and emit them all at once afterwards.

I adapted the method from https://kddsky.medium.com/pauseable-observables-in-rxjs-58ce2b8c7dfd (02/06/22)
```
merge(
  source$.pipe( bufferToggle(off$, ()=>on$)  ),
  source$.pipe( windowToggle(on$,  ()=>off$) )
).pipe(
  // then flatten buffer arrays and window Observables
  flatMap(x => x)
)
```
bufferToggle starts buffering on **_off$_**, and emits on **_on$_**
windowToggle starts emitting on **_on$_** and stops emitting on **_off$_**


P.S. 
https://kddsky.medium.com/pauseable-observables-in-rxjs-58ce2b8c7dfd (02/06/22) 
this article had another cool trick for rate-limiting for bursty events

Co-authored-by: zuozhiw <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix frontend Changes related to the frontend GUI refactor Refactor the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Slow loading times for large workflows

5 participants