@@ -122,6 +122,14 @@ public void UpdateConsoleInfo(IConsole console)
122122            cursorLeft  =  console . CursorLeft ; 
123123            cursorTop  =  console . CursorTop ; 
124124        } 
125+ 
126+         public  void  UpdateConsoleInfo ( int  bWidth ,  int  bHeight ,  int  cLeft ,  int  cTop ) 
127+         { 
128+             bufferWidth  =  bWidth ; 
129+             bufferHeight  =  bHeight ; 
130+             cursorLeft  =  cLeft ; 
131+             cursorTop  =  cTop ; 
132+         } 
125133    } 
126134
127135    internal  readonly  struct  RenderDataOffset 
@@ -212,9 +220,9 @@ private void RenderWithPredictionQueryPaused()
212220
213221        private  void  Render ( ) 
214222        { 
215-             // If there are a bunch of keys queued up, skip rendering if we've rendered 
216-             // recently. 
217-             if  ( _queuedKeys . Count  >  10  &&  ( _lastRenderTime . ElapsedMilliseconds  <  50 ) ) 
223+             // If there are a bunch of keys queued up, skip rendering if we've rendered very recently.  
224+             long   elapsedMs   =   _lastRenderTime . ElapsedMilliseconds ; 
225+             if  ( _queuedKeys . Count  >  10  &&  elapsedMs  <  50 ) 
218226            { 
219227                // We won't render, but most likely the tokens will be different, so make 
220228                // sure we don't use old tokens, also allow garbage to get collected. 
@@ -225,6 +233,20 @@ private void Render()
225233                return ; 
226234            } 
227235
236+             // If we've rendered very recently, skip the terminal window resizing check as it's unlikely 
237+             // to happen in such a short time interval. 
238+             // We try to avoid unnecessary resizing check because it requires getting the cursor position 
239+             // which would force a network round trip in an environment where front-end xtermjs talking to 
240+             // a server-side PTY via websocket. Without querying for cursor position, content written on 
241+             // the server side could be buffered, which is much more performant. 
242+             // See the following 2 GitHub issues for more context: 
243+             //  - https://github.com/PowerShell/PSReadLine/issues/3879#issuecomment-2573996070 
244+             //  - https://github.com/PowerShell/PowerShell/issues/24696 
245+             if  ( elapsedMs  <  50 ) 
246+             { 
247+                 _handlePotentialResizing  =  false ; 
248+             } 
249+ 
228250            ForceRender ( ) ; 
229251        } 
230252
@@ -928,7 +950,7 @@ void UpdateColorsIfNecessary(string newColor)
928950            _console . SetCursorPosition ( point . X ,  point . Y ) ; 
929951            _console . CursorVisible  =  true ; 
930952
931-             _previousRender . UpdateConsoleInfo ( _console ) ; 
953+             _previousRender . UpdateConsoleInfo ( bufferWidth ,   bufferHeight ,   point . X ,   point . Y ) ; 
932954            _previousRender . initialY  =  _initialY ; 
933955
934956            // TODO: set WindowTop if necessary 
0 commit comments