From 93f5de3d2957f6f30dde8ae8f588efa0754c5ca3 Mon Sep 17 00:00:00 2001 From: hashmap Date: Sat, 16 May 2020 17:12:45 +0200 Subject: [PATCH] Introduce a pause after calling Cursive.step (#3326) Currently we call it in a loop without any delays which burns cpu cycles for little value. On my machine I see decrease of cpu usage from 12% to 6% on a synced node after applying this fix. --- src/bin/tui/ui.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/bin/tui/ui.rs b/src/bin/tui/ui.rs index 804c4aea3..640af79b5 100644 --- a/src/bin/tui/ui.rs +++ b/src/bin/tui/ui.rs @@ -29,6 +29,7 @@ use cursive::utils::markup::StyledString; use cursive::views::{BoxedView, CircularFocus, Dialog, LinearLayout, Panel, StackView, TextView}; use cursive::Cursive; use std::sync::mpsc; +use std::{thread, time}; use crate::built_info; use crate::servers::Server; @@ -187,6 +188,7 @@ impl Controller { pub fn run(&mut self, server: Server) { let stat_update_interval = 1; let mut next_stat_update = Utc::now().timestamp() + stat_update_interval; + let delay = time::Duration::from_millis(50); while self.ui.step() { if let Some(message) = self.rx.try_iter().next() { match message { @@ -205,6 +207,7 @@ impl Controller { self.ui.ui_tx.send(UIMessage::UpdateStatus(stats)).unwrap(); } } + thread::sleep(delay); } server.stop(); }