public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH installer] tui: update screen during installation only when necessary
@ 2024-04-23 13:23 Christoph Heiss
  0 siblings, 0 replies; only message in thread
From: Christoph Heiss @ 2024-04-23 13:23 UTC (permalink / raw)
  To: pve-devel

This can significantly reduces CPU load and even speed up the
installation a lot on single-core machines. While the latter may not be
a realistic target for obvious reasons, lowering overall CPU usage is
always a good thing.

Also helps with flickering during the installation process quite a bit
too.

E.g. a test installation on a single-core VM goes down from 47:35 min
w/o the patch to 2:26 min w/ the patch, a ~94%(!) decrease in time.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 proxmox-tui-installer/src/main.rs             |  3 --
 .../src/views/install_progress.rs             | 32 +++++++++++--------
 2 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/proxmox-tui-installer/src/main.rs b/proxmox-tui-installer/src/main.rs
index 2462a58..4fb7afd 100644
--- a/proxmox-tui-installer/src/main.rs
+++ b/proxmox-tui-installer/src/main.rs
@@ -664,9 +664,6 @@ fn summary_dialog(siv: &mut Cursive) -> InstallerView {
 }
 
 fn install_progress_dialog(siv: &mut Cursive) -> InstallerView {
-    // Ensure the screen is updated independently of keyboard events and such
-    siv.set_autorefresh(true);
-
     let state = siv.user_data::<InstallerState>().cloned().unwrap();
     InstallerView::with_raw(&state, InstallProgressView::new(siv))
 }
diff --git a/proxmox-tui-installer/src/views/install_progress.rs b/proxmox-tui-installer/src/views/install_progress.rs
index 71af484..6453426 100644
--- a/proxmox-tui-installer/src/views/install_progress.rs
+++ b/proxmox-tui-installer/src/views/install_progress.rs
@@ -1,7 +1,7 @@
 use cursive::{
     utils::Counter,
     view::{Nameable, Resizable, ViewWrapper},
-    views::{Dialog, DummyView, LinearLayout, PaddedView, ProgressBar, TextContent, TextView},
+    views::{Dialog, DummyView, LinearLayout, PaddedView, ProgressBar, TextView},
     CbSink, Cursive,
 };
 use serde::Deserialize;
@@ -21,15 +21,15 @@ pub struct InstallProgressView {
 }
 
 impl InstallProgressView {
+    const PROGRESS_TEXT_VIEW_ID: &str = "progress-text";
+
     pub fn new(siv: &mut Cursive) -> Self {
         let cb_sink = siv.cb_sink().clone();
         let state = siv.user_data::<InstallerState>().unwrap();
-        let progress_text = TextContent::new("starting the installation ..");
 
         let progress_task = {
-            let progress_text = progress_text.clone();
             let state = state.clone();
-            move |counter: Counter| Self::progress_task(counter, cb_sink, state, progress_text)
+            move |counter: Counter| Self::progress_task(counter, cb_sink, state)
         };
 
         let progress_bar = ProgressBar::new().with_task(progress_task).full_width();
@@ -41,7 +41,11 @@ impl InstallProgressView {
             LinearLayout::vertical()
                 .child(PaddedView::lrtb(1, 1, 0, 0, progress_bar))
                 .child(DummyView)
-                .child(TextView::new_with_content(progress_text).center())
+                .child(
+                    TextView::new("starting the installation ..")
+                        .center()
+                        .with_name(Self::PROGRESS_TEXT_VIEW_ID),
+                )
                 .child(PaddedView::lrtb(
                     1,
                     1,
@@ -54,12 +58,7 @@ impl InstallProgressView {
         Self { view }
     }
 
-    fn progress_task(
-        counter: Counter,
-        cb_sink: CbSink,
-        state: InstallerState,
-        progress_text: TextContent,
-    ) {
+    fn progress_task(counter: Counter, cb_sink: CbSink, state: InstallerState) {
         let mut child = match spawn_low_level_installer(state.in_test_mode) {
             Ok(child) => child,
             Err(err) => {
@@ -129,13 +128,18 @@ impl InstallProgressView {
                     }),
                     UiMessage::Progress { ratio, text } => {
                         counter.set((ratio * 100.).floor() as usize);
-                        progress_text.set_content(text);
-                        Ok(())
+                        cb_sink.send(Box::new(move |siv| {
+                            siv.call_on_name(Self::PROGRESS_TEXT_VIEW_ID, |v: &mut TextView| {
+                                v.set_content(text);
+                            });
+                        }))
                     }
                     UiMessage::Finished { state, message } => {
                         counter.set(100);
-                        progress_text.set_content(message.to_owned());
                         cb_sink.send(Box::new(move |siv| {
+                            siv.call_on_name(Self::PROGRESS_TEXT_VIEW_ID, |v: &mut TextView| {
+                                v.set_content(&message);
+                            });
                             Self::prepare_for_reboot(siv, state == "ok", &message);
                         }))
                     }
-- 
2.44.0



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-23 13:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-23 13:23 [pve-devel] [PATCH installer] tui: update screen during installation only when necessary Christoph Heiss

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal