public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer] tui: update screen during installation only when necessary
Date: Tue, 23 Apr 2024 15:23:39 +0200	[thread overview]
Message-ID: <20240423132341.570192-1-c.heiss@proxmox.com> (raw)

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


                 reply	other threads:[~2024-04-23 13:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240423132341.570192-1-c.heiss@proxmox.com \
    --to=c.heiss@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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