Repository: microsoft/terminal (language: cpp)

Issue:
Responsiveness regression in Windows Console Host
### Windows Terminal version

1.17.11461.0

### Windows Console Host version

1.17.2305.26001 (From right-click -> properties -> details)

### Windows build number

10.0.19045.3086

### Other Software

[Typometer 1.1.0](https://github.com/frarees/typometer/releases/tag/v1.1.0)

### Steps to reproduce

1. On Windows 10, run `conhost.exe` and use typometer to measure the latency of a `cmd` prompt. I get an average of 16.3 ms with a standard deviation of 0.3 ms. Marvelous. See the first screenshot.
2. Download the latest Windows Terminal zip and measure the latency of `OpenConsole.exe`. I get an average of 28.9 ms with a standard deviation of 7.2 ms. See the second screenshot.

![image](https://github.com/microsoft/terminal/assets/29077900/81445d83-0748-4d74-a25b-438d30a0bd39)
![image](https://github.com/microsoft/terminal/assets/29077900/df2d981b-a8da-4ff7-95bf-4dfc5405ab50)



### Expected Behavior

I would like the new versions of conhost to have latency numbers closer to that of old conhost.

### Actual Behavior

Latency in new versions of conhost is quite a bit worse.


Discussion / hints:

Fix patch:
diff --git a/src/renderer/base/thread.cpp b/src/renderer/base/thread.cpp
index 056749f3e4f..904cf2075a2 100644
--- a/src/renderer/base/thread.cpp
+++ b/src/renderer/base/thread.cpp
@@ -169,6 +169,11 @@ DWORD WINAPI RenderThread::_ThreadProc()
 {
     while (_fKeepRunning)
     {
+        // Between waiting on _hEvent and calling PaintFrame() there should be a minimal delay,
+        // so that a key press progresses to a drawing operation as quickly as possible.
+        // As such, we wait for the renderer to complete _before_ waiting on _hEvent.
+        _pRenderer->WaitUntilCanRender();
+
         WaitForSingleObject(_hPaintEnabledEvent, INFINITE);
 
         if (!_fNextFrameRequested.exchange(false, std::memory_order_acq_rel))
@@ -209,10 +214,7 @@ DWORD WINAPI RenderThread::_ThreadProc()
         }
 
         ResetEvent(_hPaintCompletedEvent);
-
-        _pRenderer->WaitUntilCanRender();
         LOG_IF_FAILED(_pRenderer->PaintFrame());
-
         SetEvent(_hPaintCompletedEvent);
     }
 


Test patch: