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.
This commit is contained in:
hashmap 2020-05-16 17:12:45 +02:00 committed by GitHub
parent 133a8da53e
commit 93f5de3d29
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -29,6 +29,7 @@ use cursive::utils::markup::StyledString;
use cursive::views::{BoxedView, CircularFocus, Dialog, LinearLayout, Panel, StackView, TextView}; use cursive::views::{BoxedView, CircularFocus, Dialog, LinearLayout, Panel, StackView, TextView};
use cursive::Cursive; use cursive::Cursive;
use std::sync::mpsc; use std::sync::mpsc;
use std::{thread, time};
use crate::built_info; use crate::built_info;
use crate::servers::Server; use crate::servers::Server;
@ -187,6 +188,7 @@ impl Controller {
pub fn run(&mut self, server: Server) { pub fn run(&mut self, server: Server) {
let stat_update_interval = 1; let stat_update_interval = 1;
let mut next_stat_update = Utc::now().timestamp() + stat_update_interval; let mut next_stat_update = Utc::now().timestamp() + stat_update_interval;
let delay = time::Duration::from_millis(50);
while self.ui.step() { while self.ui.step() {
if let Some(message) = self.rx.try_iter().next() { if let Some(message) = self.rx.try_iter().next() {
match message { match message {
@ -205,6 +207,7 @@ impl Controller {
self.ui.ui_tx.send(UIMessage::UpdateStatus(stats)).unwrap(); self.ui.ui_tx.send(UIMessage::UpdateStatus(stats)).unwrap();
} }
} }
thread::sleep(delay);
} }
server.stop(); server.stop();
} }