https://x.com/elonmusk/status/2116019939056513218?a=jlQeTXtkHiUY35OdsQ4&s=20
Speech to text won't be necessary anymore?
https://x.com/elonmusk/status/2116019939056513218?a=jlQeTXtkHiUY35OdsQ4&s=20
Speech to text won't be necessary anymore?

Getting a WinUI 3 app to feel fast took more work than we expected. Here’s what we learned while fixing slow window openings and restores in Sonik.
Opening a small desktop window should feel uneventful. You click, and your interface appears.
While building Sonik, a Windows transcription app, we instead watched our windows assemble themselves: first the title bar and border, then a plain background, then the text and buttons. The whole sequence was short, but noticeable. Sometimes restoring an existing window felt slower than opening a much heavier application.
We eventually found a combination that made taskbar restores, history editors, and tray reopening feel substantially better. There was no single switch that fixed all three. They were different lifecycle problems, and treating them separately was the turning point.
This article describes the implementation we kept, the experiments we rejected, and how we measured the result. Our application uses C#, .NET 8, and WinUI 3; the implementation described here references Windows App SDK 1.8.260921001 and was tested on Windows 11. The native-message workaround below is an application-tested workaround, not a Microsoft-endorsed general solution. Recheck it when changing runtime versions.
We had four paths that looked similar to a user but did different work:
| User action | What the application needs to do |
|---|---|
| Launch the process | Initialize the application and create its first window. |
| Restore from the taskbar | Present an existing, minimized window. |
| Expand a history item | Obtain the item’s data and show an independent editor window. |
| Reopen from the tray | Bring back the main window after its Close button dismissed it. |
Moving database access or other expensive work out of constructors is worthwhile. It cannot, however, explain every slow restore: an existing window need not run its constructor again.
We reproduced staged presentation in a plain WinUI baseline and in Release builds. We also observed staged appearance in another desktop application. This stopped us from assuming that every blank frame was caused by Sonik loading history or rebuilding controls.
Our final changes primarily improve the last three paths. They do not eliminate all stages of a cold process launch. That remains a separate measurement and optimization problem.
A window can win a time-to-first-pixel benchmark by showing an empty border very quickly.
We recorded three milestones:
The second was the useful target. A textbox’s focus underline appearing later is different from the entire textbox appearing later.
Whole-desktop recording mattered. The reported problem involved the native frame and client content appearing at different times, so a capture of only the application surface was not sufficient evidence. We used timestamped desktop-duplication captures, inspected frame contact sheets, and tested real taskbar clicks and the application’s real editor-opening path.
We also checked for dropped capture frames. Eventually we buffered capture data in memory and wrote it after recording, so disk writes were less likely to interfere with the observation. Runs with missing frames, incorrect foreground ownership, or clicks blocked by a dialog were excluded.
One failed experiment taught us another lesson: verify the final reference image itself. An analyzer that compares early frames to an empty final window can report a perfectly presented window that never displayed its controls.
These measurements observe captured desktop output, not physical monitor scanout. They are useful comparative evidence, not a universal latency guarantee.
The most effective restore experiment changed what happened while the window was minimized, rather than adding more work when it was restored.
We attached a native window subclass and intercepted WM_WINDOWPOSCHANGED only when the window was iconic—Win32 terminology for minimized—and its DPI had not changed. In that case we called DefWindowProcW directly. All other messages followed the normal subclass chain through DefSubclassProc.
Those functions are not interchangeable. DefSubclassProc invokes the next handler in the subclass chain. Calling DefWindowProcW directly bypasses that remaining chain for the intercepted message.
We did not simply return zero and discard the notification. Microsoft documents that default processing of WM_WINDOWPOSCHANGED sends WM_SIZE and WM_MOVE. Preserving native default processing avoided problems seen in an earlier experiment that swallowed the message.
Here is the essential callback logic, simplified from our implementation. This is an excerpt, not a complete interop helper:
private const uint WM_WINDOWPOSCHANGED = 0x0047;
private const uint WM_DPICHANGED = 0x02E0;
private uint lastVisibleDpi;
private bool dpiChangedWhileMinimized;
private nint Receive(
nint hwnd, uint message, nuint wParam, nint lParam,
nuint subclassId, nuint referenceData)
{
if (message == WM_DPICHANGED && IsIconic(hwnd))
dpiChangedWhileMinimized = true;
if (message == WM_WINDOWPOSCHANGED)
{
if (IsIconic(hwnd))
{
uint dpi = GetDpiForWindow(hwnd);
if (!dpiChangedWhileMinimized &&
dpi != 0 && dpi == lastVisibleDpi)
{
return DefWindowProcW(hwnd, message, wParam, lParam);
}
}
else
{
nint result = DefSubclassProc(hwnd, message, wParam, lParam);
lastVisibleDpi = GetDpiForWindow(hwnd);
dpiChangedWhileMinimized = false;
return result;
}
}
return DefSubclassProc(hwnd, message, wParam, lParam);
}
The surrounding helper is just as important: initialize the DPI baseline when attaching, install the subclass on the window’s thread, keep the managed callback delegate alive, and remove the subclass when the window closes, with destruction cleanup as a fallback. Record attachment failures instead of assuming the optimization is active. Microsoft’s subclass helpers do not support cross-thread subclassing.
We conservatively use the normal framework path if DPI changes while minimized, the current DPI differs from the last visible value, or the DPI query fails. Our physical mixed-monitor DPI coverage is still incomplete; this fallback is a precaution, not proof of mixed-DPI correctness.
The experiment implicates processing in the minimized window-position path. It does not establish the exact internal WinUI operation responsible for the missing-content frames. We should not turn an observed workaround into a confident story about the framework destroying or rebuilding its visual tree.
The accepted restore path keeps the native title bar and does not wait for a rendering event before revealing the window. It also does not display a screenshot in place of live content.
In one real-app validation, four main-window restore cycles had a median first-visible time of approximately 26 ms, with complete content in the first visible frame. History editors also showed text and actions immediately; their focus styling settled later.
This is the most invasive part of our solution. It deliberately bypasses framework processing for a narrowly selected message. Keep it isolated, retain a comparison mode, and regression-test it against the exact runtime you ship.
Do not extend it to initial window creation. We tried bypassing the first-show position handling, and the editor remained blank. The processing that can be avoided during an ordinary minimize cycle may be essential during first show.
An editor that has never been shown has no previously displayed content to restore. The taskbar treatment alone could not solve its first opening.
Our history editors are separate top-level windows, not Win32 WS_CHILD controls. We wanted several open at once, each with independent text, autosave state, and lifetime.
We adopted a single prepared spare editor:
“Background preparation” here does not mean constructing XAML controls inside Task.Run. It means deferring UI-thread work until after the main UI has begun loading. That work still consumes UI-thread time and memory.
In a small startup experiment, spare construction took about 18–21 ms and began after the main window’s first framework rendering event. We moved that construction out of the item-click path. We did not prove preparation was free or measure a precise cold-start regression bound.
Calling a constructor is not equivalent to rendering the window.
Our warm-up sequence uses DWMWA_CLOAK, calls AppWindow.Show(false) without activation, waits for rendering and a composition commit, then hides and uncloaks the spare. Microsoft describes cloaking as making a window invisible to the user while DWM still composes it.
After binding the actual item, we perform another short readiness sequence. In pseudocode:
await the spare's warm-up
bind the requested item and establish its session
remember the current foreground window
cloak the editor
enable taskbar / Alt+Tab eligibility
activate the editor
await an eligible Rendered event and RequestCommitAsync
uncloak if the editor is still alive
activate again only if no newer minimize or focus change superseded us
The wait observes CompositionTarget.Rendered, checks that the target root is loaded, and requests a commit from that root’s compositor. It also has a 500 ms timeout fallback and a close handler. Temporary rendering subscriptions and timers are removed on completion.
These APIs are useful signals, not a formal “this HWND is now on the monitor” fence. Rendered is not tied to a particular UI element. RequestCommitAsync requests a composition commit; its documentation does not promise physical presentation. The desktop recordings are what established the practical result for our application.
The timeout bounds the wait; it does not certify that rendering succeeded. A fallback may expose ordinary staged presentation. Preparation failures close the failed spare and allow ordinary construction rather than leaving an invisible editor stranded.
We tried omitting the explicit commit wait. The first rectangle appeared sooner, but blank or native-frame-only frames returned. That was a faster number for a worse result, so we rejected it.
We maintain an item-keyed registry of open editor sessions. Opening an already-open item activates its editor. Opening a different item consumes another spare and leaves existing editors alone.
Each prepared editor belongs to at most one item session. We do not recycle an old item’s event handlers or storage lease onto a different item. A short asynchronous gate serializes opening setup; it is released after reveal, not held until that editor closes.
Shutdown cancels pending openings and cleans up unused spares. Closing or minimizing during the render wait must not cause the continuation to resurrect the window. Likewise, a user who changes focus during the wait should not have focus stolen back at the end.
These details deserved tests of their own: simultaneous editors, duplicate requests for the same item, independent dirty drafts, failed saves, pending opens during shutdown, and close/minimize during reveal.
In the accepted three-editor capture, the windows appeared with their correct text and actions at approximately 84, 75, and 81 ms after automated input. Earlier editors remained open. All three captures covered the following 500 ms without accumulated-frame loss. This was a small sample using synthetic content through the real store and editor path, not a promise that every editor opens within 85 ms.
Tray reopening initially needed its own workaround: activate a hidden window while cloaked, wait for rendering, then reveal it. It looked complete but felt slower than taskbar restore.
The simpler final approach was to make tray reopening use the already-fast minimized-window path.
When the user clicks Close, we cancel actual destruction, minimize the main window, and exclude it from system switchers. When the tray asks to reopen it, we restore switcher eligibility and activate that same window.
The important change was how we parked the window. We already retained its instance when using Hide(). Merely keeping a reference was not the missing optimization.
The core operations look like this inside a WinUI Window:
private bool parkedInTray;
private bool ParkInTray()
{
if (AppWindow.Presenter is not OverlappedPresenter presenter)
return false;
parkedInTray = true;
presenter.Minimize();
AppWindow.IsShownInSwitchers = false;
return true;
}
private bool RestoreFromTray()
{
if (!parkedInTray)
return false;
parkedInTray = false;
AppWindow.IsShownInSwitchers = true;
Activate();
return true;
}
This excerpt assumes the minimized-message treatment described earlier is attached. The closing handler must distinguish ordinary Close from actual application Quit: cancel Close and park the window, but let Quit destroy it. Keep an ordinary hide/reveal fallback for unsupported presenter states.
IsShownInSwitchers controls eligibility for system representations such as the taskbar and Alt+Tab. We verified taskbar removal and the property state; that should not be mistaken for exhaustive visual Alt+Tab testing.
This path adds no render-readiness wait to each tray reopen. It uses the real retained UI, so it also avoids maintaining a snapshot that might become stale.
Our final five-cycle capture measured approximately 62, 17, 13, 20, and 13 ms to first visible content. All showed text and controls in that first visible frame. The earlier hidden-window wait measured roughly 50–58 ms in a separate small run. Later warm tray reopens were clearly encouraging, but the first cycle was not faster, and these were not statistically matched trials.
Keeping a window alive has a cost. Its controls, subscriptions, and other retained resources still exist. Check idle resource use, updates while parked, and actual shutdown. A window being absent from the taskbar does not mean its application work has stopped.
Several plausible ideas failed to solve our measured problem:
None of these results says the techniques are useless in every application. It says they did not satisfy our particular acceptance test.
Before adopting these changes, test more than an empty sample window:
Our cross-monitor DPI qualification remained outstanding. We also observed handle growth shared by comparison variants; the small samples did not establish its cause or leak freedom. Those are separate lifecycle questions, not reasons to declare every visually successful capture a complete performance qualification.
We kept three distinct strategies:
| Path | Adopted behavior |
|---|---|
| Taskbar restore | Narrow same-DPI minimized-position handling; no added reveal wait. |
| New history editor | One prepared spare, independent item sessions, bounded render-and-commit reveal. |
| Tray reopen | Minimize the retained main window outside switchers, then activate it again. |
The biggest lesson was to stop treating all appearances of a window as the same operation. Preserve an existing window where that helps. Prepare new windows where construction and initial rendering are unavoidable. Measure the complete interface, not just the earliest border.
That gave us a much snappier application without replacing WinUI, discarding the native title bar, or pretending that a rendering callback proves what the user actually saw.
[> theo: codex system prompt is not very good
me, remembering uncle peter said basically all chat apps inject a huge system prompt: great that codex allows us to customize it, interesting to see how far I can take it](https://x.com/Hans_Peter_Buhr/status/2078552774631969180?s=20)
Embedded video
https://www.youtube.com/watch?v=8GRmLR__OGQ
https://www.youtube.com/watch?v=9tGrhrVKCrE
https://x.com/SemiAnalysis_/status/2064815044085318040?s=20
https://x.com/kimmonismus/status/2074078414705955006?s=20
I've found value in spending the few minutes for setting up the hotkey and using for the first time really the popup feature of codex. It's useful for the little tasks you have throughout the day, and especially on windows where window management is generally more painful. A hotkey opens the popup, and it disappears on loss of focus. (Which is a bit unexpected as you can't find the window using alt+tab, you have to reopen it using the shortcut again, but I guess you can get used to it.) It opens a project-less chat by default, which is a good default in my opinion, and doesn't take up a lot of screen space so it's more handy when you have something to do in concert with other windows (file browsers, image viewers, web pages, etc., etc.).
It's better to use software which allows you to take out your data.
It's better to use software which allows you to take out your data.