mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Cache TUI flex heights across frame passes (#34348)
## Why Sizing, rendering, and cursor placement can query the same chat widget layout multiple times in one frame, repeatedly measuring active transcript cells. ## What changed - Build one chat widget renderable tree per frame and reuse it for sizing, rendering, and cursor placement. - Cache each flex child's desired height by width for the lifetime of that tree. - Reuse the bottom pane's renderable directly instead of forwarding each renderable operation through a wrapper. ## Testing - Verify flex layouts measure a child once across frame passes and remeasure it when the width changes. - Verify a chat widget frame measures its active transcript cell once. GitOrigin-RevId: 5ad1a6711f4011c699b5d002b13dc3319cb4db8e
This commit is contained in:
1 parent
ada5a79ddf
commit
eceb3eeaf3
7 files changed
+141
-90
No files matched your search
@@ -20,6 +20,7 @@ use crate::app_event::HistoryBatchEntryResponse;
|
||||
use crate::chatwidget::ChatWidgetInit;
|
||||
use crate::chatwidget::create_initial_user_message;
|
||||
use crate::chatwidget::tests::helpers::render_bottom_popup;
|
||||
use crate::chatwidget::tests::helpers::set_active_cell;
|
||||
use crate::chatwidget::tests::make_chatwidget_manual_with_sender;
|
||||
use crate::chatwidget::tests::set_chatgpt_auth;
|
||||
use crate::chatwidget::tests::set_fast_mode_test_catalog;
|
||||
@@ -116,11 +117,14 @@ use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use crossterm::event::KeyModifiers;
|
||||
use insta::assert_snapshot;
|
||||
use pretty_assertions::assert_eq;
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::prelude::Line;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::atomic::Ordering;
|
||||
use tempfile::tempdir;
|
||||
use tokio::time;
|
||||
|
||||
@@ -136,6 +140,49 @@ fn test_absolute_path(path: &str) -> AbsolutePathBuf {
|
||||
AbsolutePathBuf::try_from(PathBuf::from(path)).expect("absolute test path")
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn chat_widget_frame_reuses_active_cell_height_across_frame_passes() {
|
||||
#[derive(Debug)]
|
||||
struct CountingHistoryCell {
|
||||
desired_height_calls: Arc<AtomicUsize>,
|
||||
}
|
||||
|
||||
impl HistoryCell for CountingHistoryCell {
|
||||
fn display_lines(&self, _width: u16) -> Vec<Line<'static>> {
|
||||
vec![Line::from("active cell")]
|
||||
}
|
||||
|
||||
fn raw_lines(&self) -> Vec<Line<'static>> {
|
||||
vec![Line::from("active cell")]
|
||||
}
|
||||
|
||||
fn desired_height(&self, _width: u16) -> u16 {
|
||||
self.desired_height_calls.fetch_add(1, Ordering::Relaxed);
|
||||
1
|
||||
}
|
||||
}
|
||||
|
||||
let mut app = make_test_app().await;
|
||||
let desired_height_calls = Arc::new(AtomicUsize::new(0));
|
||||
set_active_cell(
|
||||
&mut app.chat_widget,
|
||||
Box::new(CountingHistoryCell {
|
||||
desired_height_calls: Arc::clone(&desired_height_calls),
|
||||
}),
|
||||
);
|
||||
let width = 80;
|
||||
app.with_chat_widget_frame(width, |desired_height, chat_widget| {
|
||||
let area = Rect::new(/*x*/ 0, /*y*/ 0, width, desired_height);
|
||||
let mut buffer = Buffer::empty(area);
|
||||
|
||||
chat_widget.render(area, &mut buffer);
|
||||
assert!(chat_widget.cursor_pos(area).is_some());
|
||||
let _ = chat_widget.cursor_style(area);
|
||||
});
|
||||
|
||||
assert_eq!(desired_height_calls.load(Ordering::Relaxed), 1);
|
||||
}
|
||||
|
||||
async fn next_thread_settings_updated(
|
||||
app_server: &mut AppServerSession,
|
||||
thread_id: ThreadId,
|
||||
|
||||
Reference in new issue
Block a user