refactor: reduce lines of log cloned

Instead of cloning every single line of logs, now we only clone those logs that are visible +- a padding.

Containers with hunders or thousands of lines of logs can see a huge reducing in CPU and memory usage
This commit is contained in:
Jack Wills
2025-06-16 20:54:40 +00:00
parent e7114d2f5e
commit ecefa302b9
3 changed files with 82 additions and 7 deletions
+3 -1
View File
@@ -39,7 +39,8 @@ pub fn draw(
}
f.render_widget(paragraph, area);
} else {
let logs = app_data.lock().get_logs();
let padding = usize::from(area.height / 5);
let logs = app_data.lock().get_logs(area.height, padding);
if logs.is_empty() {
let mut paragraph = Paragraph::new("no logs found")
.block(block)
@@ -52,6 +53,7 @@ pub fn draw(
let items = List::new(logs)
.block(block)
.highlight_symbol(RIGHT_ARROW)
.scroll_padding(padding)
.highlight_style(Style::default().add_modifier(Modifier::BOLD));
// This should always return Some, as logs is not empty
if let Some(log_state) = app_data.lock().get_log_state() {