Skip to content

[FEAT] cache mechanism in DAG layout in console monitor#699

Merged
gbin merged 3 commits into
masterfrom
yang/fix/dag_navigation
Jan 22, 2026
Merged

[FEAT] cache mechanism in DAG layout in console monitor#699
gbin merged 3 commits into
masterfrom
yang/fix/dag_navigation

Conversation

@makeecat

Copy link
Copy Markdown
Collaborator

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.rs

New caching infrastructure:

  • Added GraphCacheKey struct (lines 375-380) to track cache validity based on area size, node
    count, and connection count
  • Added GraphCache struct (lines 382-405) to store the computed NodeGraph, content size, and cache
    key
  • Added needs_rebuild() method to determine when cache invalidation is needed

Refactored NodesScrollableWidgetState:

  • Moved graph building logic from StatefulWidget::render() into state methods:
    • ensure_graph_cache() - lazily initializes/rebuilds cache as needed
    • rebuild_graph_cache() - performs actual graph computation and layout
    • build_graph() / build_node_layouts() - extracted helper methods
    • clamp_scroll_offset() - ensures scroll position stays within bounds
    • mark_graph_dirty() - called on window resize to force rebuild

Simplified render method:

  • NodesScrollableWidget::render() now simply calls state.ensure_graph_cache(area) and uses the cached graph
  • Removed the inline GraphWrapper struct (now uses &NodeGraph directly)
  • Minor code cleanups: simplified index clamping, extracted repeated node variable

Resize handling:

  • Added mark_graph_dirty() call on Event::Resize to invalidate cache when terminal size changes

Changes in cu_consolemon/src/tui_nodes/graph.rs

  • Extracted render logic into render_into(&self, ...) method to allow rendering from a reference
  • Changed node iteration from into_iter() to iter() to avoid consuming the graph
  • Added Widget impl for &'a NodeGraph<'a> (lines 420-424) enabling the graph to be rendered by reference

@makeecat makeecat requested a review from gbin January 21, 2026 19:44
@makeecat makeecat self-assigned this Jan 21, 2026
@makeecat makeecat added the enhancement New feature or request label Jan 21, 2026
@makeecat makeecat linked an issue Jan 22, 2026 that may be closed by this pull request
@gbin

gbin commented Jan 22, 2026

Copy link
Copy Markdown
Collaborator

wow ok, this is going waaay better now :)

@gbin gbin merged commit 318492b into master Jan 22, 2026
23 checks passed
@gbin gbin deleted the yang/fix/dag_navigation branch January 22, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Navigating the DAG in consolemon is too slow

2 participants