mirror of
https://github.com/extrawurst/gitui.git
synced 2024-12-28 19:44:14 +03:00
Fix external editor delay. (#1579)
The default polling rate of 1 second causes a 1 second delay when queuing the event to launch the external editor, causing latency. However, a slower polling helps reduce CPU usage, so let's have a short polling duration as long as there are input events, and slow poll otherwise. Since the external editor among other components (not tested) is always launched in response to an input event, we reduce the latency to ~100ms, which is the fast poll duration. Co-authored-by: extrawurst <776816+extrawurst@users.noreply.github.com>
This commit is contained in:
parent
6ec647710d
commit
bf31f20657
10
src/input.rs
10
src/input.rs
@ -11,7 +11,8 @@ use std::{
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
static POLL_DURATION: Duration = Duration::from_millis(1000);
|
||||
static FAST_POLL_DURATION: Duration = Duration::from_millis(100);
|
||||
static SLOW_POLL_DURATION: Duration = Duration::from_millis(1000);
|
||||
|
||||
///
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
@ -103,6 +104,7 @@ impl Input {
|
||||
arc_current: &Arc<AtomicBool>,
|
||||
tx: &Sender<InputEvent>,
|
||||
) -> Result<()> {
|
||||
let mut poll_duration = SLOW_POLL_DURATION;
|
||||
loop {
|
||||
if arc_desired.get() {
|
||||
if !arc_current.load(Ordering::Relaxed) {
|
||||
@ -112,14 +114,18 @@ impl Input {
|
||||
}
|
||||
arc_current.store(true, Ordering::Relaxed);
|
||||
|
||||
if let Some(e) = Self::poll(POLL_DURATION)? {
|
||||
if let Some(e) = Self::poll(poll_duration)? {
|
||||
// windows send key release too, only process key press
|
||||
if let Key(key) = e {
|
||||
if key.kind != KeyEventKind::Press {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
tx.send(InputEvent::Input(e))?;
|
||||
poll_duration = FAST_POLL_DURATION;
|
||||
} else {
|
||||
poll_duration = SLOW_POLL_DURATION;
|
||||
}
|
||||
} else {
|
||||
if arc_current.load(Ordering::Relaxed) {
|
||||
|
Loading…
Reference in New Issue
Block a user