[FEAT] cache mechanism in DAG layout in console monitor#699
Merged
Conversation
Collaborator
|
wow ok, this is going waaay better now :) |
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.
Summary
This PR adds a caching mechanism for the DAG (Directed Acyclic Graph) layout in the console monitor to improve scrolling performance. Previously, the graph was rebuilt on every render frame; now it's cached and only rebuilt when necessary (on resize or graph structure changes).
Related Issue: #683
Details
Changes in
cu_consolemon/src/lib.rsNew caching infrastructure:
GraphCacheKeystruct (lines 375-380) to track cache validity based on area size, nodecount, and connection count
GraphCachestruct (lines 382-405) to store the computed NodeGraph, content size, and cachekey
needs_rebuild()method to determine when cache invalidation is neededRefactored NodesScrollableWidgetState:
StatefulWidget::render()into state methods:ensure_graph_cache()- lazily initializes/rebuilds cache as neededrebuild_graph_cache()- performs actual graph computation and layoutbuild_graph()/build_node_layouts()- extracted helper methodsclamp_scroll_offset()- ensures scroll position stays within boundsmark_graph_dirty()- called on window resize to force rebuildSimplified render method:
NodesScrollableWidget::render()now simply callsstate.ensure_graph_cache(area)and uses the cached graph&NodeGraphdirectly)Resize handling:
mark_graph_dirty()call onEvent::Resizeto invalidate cache when terminal size changesChanges in
cu_consolemon/src/tui_nodes/graph.rsrender_into(&self, ...)method to allow rendering from a referenceinto_iter()toiter()to avoid consuming the graph&'a NodeGraph<'a>(lines 420-424) enabling the graph to be rendered by reference