From 3bb0adaa75769413d87b1a95f371f1facc448d49 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sun, 26 Feb 2023 10:51:59 -0600 Subject: [PATCH] fix: do not re-render unless needed Previously, dune would re-render on every frame even when it wasn't necessary. Now, dune will make sure we have at least one modification before re-rendering Signed-off-by: Rudi Grinberg --- CHANGES.md | 3 +++ .../dune_threaded_console.ml | 16 +++++++++++++--- .../dune_threaded_console_intf.ml | 1 + 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index a541e61f589..1d9a310b063 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,9 @@ Unreleased ---------- +- Do not re-render UI on every frame if the UI doesn't change (#7186, fix + #7184, @rgrinberg) + - Fix preludes not being recorded as dependencies in the `(mdx)` stanza (#7109, fixes #7077, @emillon). diff --git a/src/dune_threaded_console/dune_threaded_console.ml b/src/dune_threaded_console/dune_threaded_console.ml index 966b5c296dd..139148fca10 100644 --- a/src/dune_threaded_console/dune_threaded_console.ml +++ b/src/dune_threaded_console/dune_threaded_console.ml @@ -16,10 +16,12 @@ let make (module Base : S) : (module Dune_console.Backend) = ; status_line = None ; finished = false ; finish_requested = false + ; dirty = true } let finish () = Mutex.lock mutex; + state.dirty <- true; state.finish_requested <- true; while not state.finished do Condition.wait finish_cv mutex @@ -28,11 +30,13 @@ let make (module Base : S) : (module Dune_console.Backend) = let print_user_message m = Mutex.lock mutex; + state.dirty <- true; Queue.push state.messages m; Mutex.unlock mutex let set_status_line sl = Mutex.lock mutex; + state.dirty <- true; state.status_line <- sl; Mutex.unlock mutex @@ -40,6 +44,7 @@ let make (module Base : S) : (module Dune_console.Backend) = let reset () = Mutex.lock mutex; + state.dirty <- true; Queue.clear state.messages; state.status_line <- None; Base.reset (); @@ -47,6 +52,7 @@ let make (module Base : S) : (module Dune_console.Backend) = let reset_flush_history () = Mutex.lock mutex; + state.dirty <- true; Queue.clear state.messages; state.status_line <- None; Base.reset_flush_history (); @@ -84,9 +90,13 @@ let make (module Base : S) : (module Dune_console.Backend) = events and sleep for the remaining time. *) while true do Mutex.lock mutex; - Base.render state; - let finish_requested = state.finish_requested in - if finish_requested then raise_notrace Exit; + (match state.dirty with + | false -> () + | true -> + Base.render state; + let finish_requested = state.finish_requested in + if finish_requested then raise_notrace Exit; + state.dirty <- false); Mutex.unlock mutex; let now = Unix.gettimeofday () in let elapsed = now -. !last in diff --git a/src/dune_threaded_console/dune_threaded_console_intf.ml b/src/dune_threaded_console/dune_threaded_console_intf.ml index 1ea12d0aa71..d32c534c9ae 100644 --- a/src/dune_threaded_console/dune_threaded_console_intf.ml +++ b/src/dune_threaded_console/dune_threaded_console_intf.ml @@ -7,6 +7,7 @@ type state = ; mutable finish_requested : bool ; mutable finished : bool ; mutable status_line : User_message.Style.t Pp.t option + ; mutable dirty : bool } (** [Threaded] is the interface for user interfaces that are rendered in a