diff mbox series

[bug#50634] progress: Rate limit drawing in the progress-reporter/bar.

Message ID 20210917101556.13071-1-mail@cbaines.net
State Accepted
Headers show
Series [bug#50634] progress: Rate limit drawing in the progress-reporter/bar. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Christopher Baines Sept. 17, 2021, 10:15 a.m. UTC
This helps smooth the output in cases where the bar is updated very quickly,
for example in guix weather where it's computing derivations.

* guix/progress.scm (progress-reporter/bar): Wrap the drawing code with the
rate-limited procedure.
---
 guix/progress.scm | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

Comments

Ludovic Courtès Sept. 30, 2021, 9:05 p.m. UTC | #1
Hi Christopher,

Christopher Baines <mail@cbaines.net> skribis:

> This helps smooth the output in cases where the bar is updated very quickly,
> for example in guix weather where it's computing derivations.
>
> * guix/progress.scm (progress-reporter/bar): Wrap the drawing code with the
> rate-limited procedure.

I hit that problem quite frequently lately in shell-mode so I’m grateful
you fixed it.  Go for it!

Thanks,
Ludo’.
Christopher Baines Dec. 12, 2021, 3:23 p.m. UTC | #2
Ludovic Courtès <ludo@gnu.org> writes:

> Hi Christopher,
>
> Christopher Baines <mail@cbaines.net> skribis:
>
>> This helps smooth the output in cases where the bar is updated very quickly,
>> for example in guix weather where it's computing derivations.
>>
>> * guix/progress.scm (progress-reporter/bar): Wrap the drawing code with the
>> rate-limited procedure.
>
> I hit that problem quite frequently lately in shell-mode so I’m grateful
> you fixed it.  Go for it!

I seemingly forgot about this, but I've now pushed this patch as
604880ae22e1a7662acb1d3f282242470de0cd03.

Thanks,

Chris
diff mbox series

Patch

diff --git a/guix/progress.scm b/guix/progress.scm
index 0cbc804ec1..4f8e98edc0 100644
--- a/guix/progress.scm
+++ b/guix/progress.scm
@@ -270,19 +270,25 @@  ABBREVIATION used to shorten FILE for display."
 tasks is performed.  Write PREFIX at the beginning of the line."
   (define done 0)
 
+  (define (draw-bar)
+    (let* ((ratio (* 100. (/ done total))))
+      (erase-current-line port)
+      (if (string-null? prefix)
+          (display (progress-bar ratio (current-terminal-columns)) port)
+          (let ((width (- (current-terminal-columns)
+                          (string-length prefix) 3)))
+            (display prefix port)
+            (display "  " port)
+            (display (progress-bar ratio width) port)))
+      (force-output port)))
+
+  (define draw-bar/rate-limited
+    (rate-limited draw-bar %progress-interval))
+
   (define (report-progress)
     (set! done (+ 1 done))
     (unless (> done total)
-      (let* ((ratio (* 100. (/ done total))))
-        (erase-current-line port)
-        (if (string-null? prefix)
-            (display (progress-bar ratio (current-terminal-columns)) port)
-            (let ((width (- (current-terminal-columns)
-                            (string-length prefix) 3)))
-              (display prefix port)
-              (display "  " port)
-              (display (progress-bar ratio width) port)))
-        (force-output port))))
+      (draw-bar/rate-limited)))
 
   (progress-reporter
    (start (lambda ()