feat: snapshot AppState before rendering to shorten critical section#140
Merged
Conversation
Introduce a RenderSnapshot captured quickly from AppState under the mutex lock, then release the lock before expensive frame composition. This reduces contention between UI rendering and background data collectors. Key changes: - Add RenderSnapshot struct (render_snapshot.rs) with capture() method that clones only frame-needed data; VecDeque histories converted to Vec for lighter clone - Extract all frame assembly logic into FrameRenderer (frame_renderer.rs) operating purely on the snapshot without holding any lock - Refactor UiLoop::run() so the critical section only covers mutable bookkeeping (scroll offsets, frame counter) and snapshot capture; all rendering, differential output, and stdout flushing happen after the lock is dropped - RenderSnapshot::as_app_state() provides backward compatibility with existing UI functions that accept &AppState - Add 8 unit tests covering snapshot capture, independence, and roundtrip conversion Closes #136
…rame renderer - Use saturating_sub for all arithmetic in render_disconnection_notification to prevent subtraction overflow panic with long hostnames - Truncate text that exceeds box inner width instead of panicking - Add early return guard for degenerate box_width < 6 - Pass shared view_state reference into render_gpu_section to eliminate a redundant as_app_state() allocation per frame - Pass cols/rows through to render_local_devices instead of making a redundant crossterm::terminal::size() syscall mid-render - Mark DEFAULT_TERMINAL_WIDTH/HEIGHT as dead_code now that the fallback is no longer needed in the render path
Member
Author
Code Review Summary -- PR #140Findings Addressed (commit d928467)1. [MEDIUM] Subtraction overflow panic in
2. [MEDIUM] Redundant
3. [LOW] Redundant
Findings Not Requiring Code Changes4. [LOW]
Architecture Review -- No Issues Found
Verification
|
Member
Author
PR Finalization CompleteSummary
Total test count: 216 unit tests (up from 204), all passing. |
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
RenderSnapshotstruct that captures only frame-needed data fromAppStateunder the mutex lock, then releases the lock immediately before expensive frame compositionFrameRenderermodule that operates purely on the immutable snapshot, never holding theAppStatelockUiLoop::run()critical section to cover only mutable bookkeeping (scroll offsets, frame counter) and snapshot capture; all rendering, differential output, and stdout flushing happen after lock releaseRenderSnapshot::as_app_state()provides backward compatibility bridge with existing UI functions that accept&AppStateCloses #136
Test plan
RenderSnapshot: flag preservation, tab state, scroll state, sort state, data version, VecDeque-to-Vec conversion, snapshot independence from source mutation, and roundtripas_app_state()conversioncargo clippy -- -D warningspasses with no warningscargo fmt -- --checkpassesall-smiin local mode and confirm identical visual outputall-smi viewin remote mode and confirm tab switching, scrolling, and disconnection notification work correctly