From b93b80ccaaab5fc3bb1210b70f443b0937abcbf0 Mon Sep 17 00:00:00 2001 From: Nate Mara Date: Tue, 11 May 2021 00:59:24 -0700 Subject: [PATCH] Remove unnecessary work from ps (#3407) The ps plugin has an unnecessary call to `std::thread::sleep(500ms)` that delays runtime by 500ms. Additionally, there is a call to `sysinfo::SystemExt::refresh_process`, which is not required as the previous call to sysinfo::SystemExt::refresh_all handles the "refresh" of all processes without a need to do this individually. Combining both of these improvements means that running ps runs nearly instentaneously. Fixes #3402 --- crates/nu_plugin_ps/src/ps.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/nu_plugin_ps/src/ps.rs b/crates/nu_plugin_ps/src/ps.rs index d710de253..d487de8e8 100644 --- a/crates/nu_plugin_ps/src/ps.rs +++ b/crates/nu_plugin_ps/src/ps.rs @@ -15,15 +15,12 @@ impl Ps { pub async fn ps(tag: Tag, long: bool) -> Result, ShellError> { let mut sys = System::new_all(); sys.refresh_all(); - let duration = std::time::Duration::from_millis(500); - std::thread::sleep(duration); let mut output = vec![]; let result: Vec<_> = sys.get_processes().iter().map(|x| *x.0).collect(); for pid in result.into_iter() { - sys.refresh_process(pid); if let Some(result) = sys.get_process(pid) { let mut dict = TaggedDictBuilder::new(&tag); dict.insert_untagged("pid", UntaggedValue::int(pid));