Repository navigation
perf: Keep large graphs with node views responsive - #102
Merged
Merged
Conversation
Node instance views are no longer built on every sync, node views and editors no longer take part in the page-wide Bokeh layout pass, the figure stylesheet lookup no longer searches every view on the page, and node views are searched for figures once instead of on every child change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A tree of hundreds of
Nodeinstances, each holding a small Panel card (a one-row table, two buttons and a label), took a long time to appear, and selecting a node got slower as the graph grew. I profiled a 1000-node version on the server and in Chromium and found four costs that grew with the size of the graph:_process_param_changeserialized eachNodewithto_dict(), which calls__panel__()and threw the result away. Internal callers now use the view cache, so each node's view is built once.Bokeh.index.find_by_id, which searches every view on the page. That made mounting quadratic in the number of nodes: 4.3s of the 1000-node build. Nodes now skip the lookup when their models contain no figure, and otherwise resolve their own view through the parent._patch_viewssearched every node's models for figures whenever any child changed, including on every selection. It was also passed the replaced models instead of the current ones, so on first render Python never patched a figure at all. It now searches each new model once.With 1000 nodes, views appear in 6.0s instead of 9.7s, and the side editor opens in 0.13 to 0.22s instead of 0.25 to 0.33s. I added unit tests for building views once and searching for figures once, and UI tests for the figure stylesheet and for opening the side editor without laying out node views. Each new test fails on
main, except the figure stylesheet test, which covers the new lookup path. The unit and UI suites pass.Benchmark
1000-node random tree, every node its own
Nodesubclass instance with apn.pane.DataFrame, twopmu.Buttons and apn.pane.Markdown, straight labelled edges,editor_mode="side". Headless Chromium, 1600x1000.Server side, a selection went from 690ms to 330ms. The rest is Bokeh's
DocumentModelManager.recompute, which walks every model in the document when the new editor's models are added.What is left
<text>, and Chrome re-lays out and re-shapes SVG text whenever an ancestor transform changes. During a zoom every label is invalidated on every step (37,000 invalidations over 37 steps with 999 edges). Without labels, zoom goes from about 60 to 99 fps and the long tasks disappear.text-renderingdoes not help. Moving labels to HTML throughEdgeLabelRendererwould fix it, but it changes the DOM, the label styling props and label click behaviour, so I left it for a separate change.pmu.Buttonrenders in its own shadow root with its own emotion cache, which inserts 65,000 CSS rules for 2000 buttons.