From 7f81a3d09fe0fd453b837bcc388c5d40de14231c Mon Sep 17 00:00:00 2001 From: SimaTian Date: Wed, 26 Feb 2025 11:03:25 +0100 Subject: [PATCH 1/3] asking terminal for dimensions during every frame is expensive --- .../Logging/TerminalLogger/TerminalLogger.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Build/Logging/TerminalLogger/TerminalLogger.cs b/src/Build/Logging/TerminalLogger/TerminalLogger.cs index 33696ada520..d186b1e8f0c 100644 --- a/src/Build/Logging/TerminalLogger/TerminalLogger.cs +++ b/src/Build/Logging/TerminalLogger/TerminalLogger.cs @@ -1058,11 +1058,21 @@ private void ErrorRaised(object sender, BuildErrorEventArgs e) private void ThreadProc() { // 1_000 / 30 is a poor approx of 30Hz + var count = 0; while (!_cts.Token.WaitHandle.WaitOne(1_000 / 30)) { + count++; lock (_lock) { - DisplayNodes(); + if (count > 30) + { + count = 0; + DisplayNodes(true); + } + else + { + DisplayNodes(); + } } } @@ -1073,9 +1083,11 @@ private void ThreadProc() /// Render Nodes section. /// It shows what all build nodes do. /// - internal void DisplayNodes() + internal void DisplayNodes(bool updateSize = false) { - TerminalNodesFrame newFrame = new TerminalNodesFrame(_nodes, width: Terminal.Width, height: Terminal.Height); + var width = updateSize ? Terminal.Width : _currentFrame.Width; + var height = updateSize ? Terminal.Height : _currentFrame.Height; + TerminalNodesFrame newFrame = new TerminalNodesFrame(_nodes, width: width, height: height); // Do not render delta but clear everything if Terminal width or height have changed. if (newFrame.Width != _currentFrame.Width || newFrame.Height != _currentFrame.Height) From 68351f80535a60345137a72e941b52c568499fc8 Mon Sep 17 00:00:00 2001 From: SimaTian Date: Wed, 26 Feb 2025 12:16:43 +0100 Subject: [PATCH 2/3] default change --- src/Build/Logging/TerminalLogger/TerminalLogger.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Build/Logging/TerminalLogger/TerminalLogger.cs b/src/Build/Logging/TerminalLogger/TerminalLogger.cs index d186b1e8f0c..0cb65a97212 100644 --- a/src/Build/Logging/TerminalLogger/TerminalLogger.cs +++ b/src/Build/Logging/TerminalLogger/TerminalLogger.cs @@ -1064,14 +1064,14 @@ private void ThreadProc() count++; lock (_lock) { - if (count > 30) + if (count >= 30) { count = 0; - DisplayNodes(true); + DisplayNodes(); } else { - DisplayNodes(); + DisplayNodes(false); } } } @@ -1083,7 +1083,7 @@ private void ThreadProc() /// Render Nodes section. /// It shows what all build nodes do. /// - internal void DisplayNodes(bool updateSize = false) + internal void DisplayNodes(bool updateSize = true) { var width = updateSize ? Terminal.Width : _currentFrame.Width; var height = updateSize ? Terminal.Height : _currentFrame.Height; From 20a1cfee1c4e4cddd644cf4e604819724a98b715 Mon Sep 17 00:00:00 2001 From: SimaTian Date: Thu, 27 Feb 2025 09:38:12 +0100 Subject: [PATCH 3/3] added a comment for the future --- src/Build/Logging/TerminalLogger/TerminalLogger.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Build/Logging/TerminalLogger/TerminalLogger.cs b/src/Build/Logging/TerminalLogger/TerminalLogger.cs index 0cb65a97212..64f2cd341d6 100644 --- a/src/Build/Logging/TerminalLogger/TerminalLogger.cs +++ b/src/Build/Logging/TerminalLogger/TerminalLogger.cs @@ -1064,6 +1064,7 @@ private void ThreadProc() count++; lock (_lock) { + // Querying the terminal for it's dimensions is expensive, so we only do it every 30 frames e.g. once a second. if (count >= 30) { count = 0;