Skip to content

Commit

Permalink
logs: decrease memory footprint by 30%
Browse files Browse the repository at this point in the history
We don't need original entries anymore, content + rows is enough.

And after this change for 851751 entries RSS is:
- less:  309MiB
- chdig: 570MiB (+84%)

But it is not that bad and also re-rendering is not a thing anymore (at
least when the logs are static).
  • Loading branch information
azat committed Apr 2, 2024
1 parent 1ed8ff3 commit 798fb96
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
11 changes: 4 additions & 7 deletions src/view/log_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ impl LogEntry {

#[derive(Default)]
pub struct LogViewBase {
logs: Vec<LogEntry>,
content: StyledString,
rows: Option<Vec<Row>>,
max_width: usize,
Expand Down Expand Up @@ -168,13 +167,11 @@ impl LogViewBase {
}
}

fn push_logs(&mut self, logs: &mut Vec<LogEntry>) {
let new_rows = logs.len();
self.logs.append(logs);
log::trace!("Add {} log entries (total {})", new_rows, self.logs.len());
fn push_logs(&mut self, logs: &[LogEntry]) {
log::trace!("Add {} log entries", logs.len());

// Increment content update
for log in self.logs.iter().skip(self.logs.len() - new_rows) {
for log in logs.iter() {
let mut line = log.to_styled_string(self.cluster);
line.append("\n");

Expand Down Expand Up @@ -367,7 +364,7 @@ impl LogView {
return log_view;
}

pub fn push_logs(&mut self, logs: &mut Vec<LogEntry>) {
pub fn push_logs(&mut self, logs: &[LogEntry]) {
self.inner_view.get_inner_mut().get_mut().push_logs(logs);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/view/text_log_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl TextLogView {
logs.push(log_entry);
}

self.inner_view.push_logs(&mut logs);
self.inner_view.push_logs(&logs);

return Ok(());
}
Expand Down

0 comments on commit 798fb96

Please sign in to comment.