From 8cadc5a4ac78ba95db7a59ef265f7c403e0ec8b5 Mon Sep 17 00:00:00 2001 From: Jason Gedge Date: Sun, 22 Dec 2019 14:14:03 -0330 Subject: [PATCH] Wait for process instead of polling its status. This provides a huge performance boost for pipelines that end in an external command. Rough testing shows an improvement from roughly 400ms to 30ms when `cat`-ing a large file. --- src/commands/classified/external.rs | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/commands/classified/external.rs b/src/commands/classified/external.rs index 190ff2ad5..876eac11c 100644 --- a/src/commands/classified/external.rs +++ b/src/commands/classified/external.rs @@ -170,29 +170,17 @@ pub(crate) async fn run_external_command( let name_tag = command.name_tag.clone(); if let Ok(mut popen) = popen { + popen.detach(); match stream_next { StreamNext::Last => { - popen.detach(); - loop { - match popen.poll() { - None => { - std::thread::sleep(std::time::Duration::new(0, 100_000_000)); - } - _ => { - let _ = popen.terminate(); - break; - } - } - } + let _ = popen.wait(); Ok(ClassifiedInputStream::new()) } StreamNext::External => { - popen.detach(); let stdout = popen.stdout.take().unwrap(); Ok(ClassifiedInputStream::from_stdout(stdout)) } StreamNext::Internal => { - popen.detach(); let stdout = popen.stdout.take().unwrap(); let file = futures::io::AllowStdIo::new(stdout); let stream = Framed::new(file, LinesCodec {});