reduce updates to improve performance on large repos

This commit is contained in:
Stephan Dilly 2020-03-20 12:49:58 +01:00
parent c6c1bac3b4
commit eac8488ce6
3 changed files with 18 additions and 10 deletions

View file

@ -142,9 +142,11 @@ impl App {
if !self.commit.is_visible() {
if self.index.event(ev) {
self.update();
return;
}
if self.index_wd.event(ev) {
self.update();
return;
}
if self.diff.event(ev) {
@ -172,9 +174,13 @@ impl App {
})
}
keys::STATUS_STAGE_FILE => {
self.index_add_remove()
self.index_add_remove();
self.update();
}
keys::STATUS_RESET_FILE => {
self.index_reset();
self.update();
}
keys::STATUS_RESET_FILE => self.index_reset(),
_ => (),
};
}
@ -305,6 +311,8 @@ impl App {
self.diff.focus(true);
}
};
self.update();
}
}

View file

@ -38,17 +38,17 @@ fn main() -> Result<()> {
let receiver = poll::start_polling_thread();
loop {
app.update();
terminal.draw(|mut f| app.draw(&mut f))?;
let events = receiver.recv().unwrap();
for e in events {
if let QueueEvent::Event(ev) = e {
if let QueueEvent::InputEvent(ev) = e {
app.event(ev);
} else {
app.update();
}
}
terminal.draw(|mut f| app.draw(&mut f))?;
if app.is_quit() {
break;
}

View file

@ -9,13 +9,13 @@ use std::{
#[derive(Clone)]
pub enum QueueEvent {
Tick,
Event(Event),
InputEvent(Event),
}
static MAX_POLL_DURATION: Duration = Duration::from_secs(2);
static MIN_POLL_DURATION: Duration = Duration::from_millis(5);
static MAX_BATCHING_DURATION: Duration = Duration::from_millis(25);
static TICK_DURATION: Duration = Duration::from_secs(2);
static TICK_DURATION: Duration = Duration::from_secs(5);
/// we run 2 threads feeding us with update events.
///
@ -36,7 +36,7 @@ pub fn start_polling_thread() -> Receiver<Vec<QueueEvent>> {
MIN_POLL_DURATION
};
if let Some(e) = poll(timeout) {
batch.push(QueueEvent::Event(e));
batch.push(QueueEvent::InputEvent(e));
}
if !batch.is_empty()