The typing lag we shipped with the scroll fix
SQLly 1.31.0 cut scroll CPU by caching parts of the window, and made typing 80 to 120 ms late. What broke, why, and what 1.34.2 fixes.
Earlier this week I wrote about cutting the CPU cost of scrolling the results grid. The biggest change in that work was drawing parts of the window from a cache instead of rebuilding them on every frame. It cut the CPU. It also made typing in the query editor feel slow, and I shipped that in 1.31.0 without noticing. This post covers what broke, why, and what 1.34.2 fixes.
If typing has felt laggy since 1.31.0, update to 1.34.2.
On a connected tab, each character you typed reached the screen 80 to 120 ms late, even in an empty editor. That is fixed, along with five smaller bugs from the same cause.
What the scroll work changed
GPUI, the UI framework SQLly is built on, normally rebuilds every view on every frame. The scroll work put the editor, the explorer sidebar, the menu bar, the tab strip and the status bar behind a cache. A cached view is drawn from its previous frame until it says it has changed.
That last part is the catch. Before the cache, a view could change its state and say nothing, and the change still appeared, because some other part of the window would cause a frame and everything was rebuilt. After the cache, a view that changes without saying so stays on its old picture until something else happens to wake it.
I knew this rule when I wrote the first post. It’s in the list of things I said the cache depends on. What I didn’t do was go through every place the cached views change state and check that each one says so. I tested hovering, tabs, pickers and popovers. I didn’t test typing closely enough to see a tenth of a second.
The typing lag
When you type a character, the editor updates its text and then decides what else to do. On a tab with a connection, the next step is to schedule the completion popup, which waits 120 ms so a burst of typing only asks once. That path scheduled the popup and returned. It never asked for a repaint.
Before the cache nobody could tell. The edit also told the app the tab had changed, the app drew a frame, and the editor was rebuilt with it. After the cache, that frame drew the editor from its previous picture, without the new character. The character appeared when one of the editor’s own delayed tasks finished: the insert-hint pass at 80 ms or the completion pass at 120 ms.
So the editor wasn’t busy. It had the character straight away and showed it late. That is why it felt just as slow with an empty editor as with a long script. The fix is one line: the editor now asks for a repaint on every edit.
An idle window that kept drawing
While looking at that, I found the opposite problem in the tab strip and status bar. Those two rows read from too many places to audit, so the first post gave them a safety rule: never draw from a cache more than a fifth of a second old. Each row had its own timer for that.
The two timers kept each other alive. When the tab strip’s timer fired, the window drew a frame. That frame refreshed the tab strip, and left the status bar one frame behind, so the status bar set a timer. When that fired, the tab strip was the one left behind. In a test window that nobody touched, each row was rebuilt about twelve times a second, for as long as the window was open, and each of those frames also rebuilt the rest of the uncached window.
That is a small, steady cost on a laptop sitting idle. I haven’t measured it as battery or CPU, so I won’t put a number on it. The two rows now share one timer. When it fires it checks whether the last frame drew either row from its cache. If so, it refreshes both in one frame. If not, it does nothing, and the window goes quiet. The fifth-of-a-second rule during a scroll is unchanged.
What else turned up
One bug of this kind suggested there were more, so I went through the editor, the sidebar, the menu bar and the two chrome rows looking for state that changes without a repaint request. Five more were real:
| What you would have seen | Why |
|---|---|
| After closing a dialog or switching split panes, typing did nothing until you clicked the editor. | The editor takes keyboard focus when it next redraws. The request for focus never asked for that redraw. |
| The editor’s scrollbar was missing or the wrong size after a large paste or delete, until you moved the caret. | The scrollbar is sized from the previous layout. Nothing redrew the editor after the new layout. |
| The explorer’s scrollbar was wrong after a server’s children loaded, and a big height change could leave blank rows at the bottom. | The same thing in the explorer tree, which also decides which rows to build from the previous layout. |
| The sidebar, AI and results toggles in the title bar didn’t follow their keyboard shortcuts until something else redrew. | The menu bar was told about the change in the middle of drawing a frame, which is too late for that frame and doesn’t schedule another. |
| Azure servers found while the explorer was empty didn’t appear until you moved the pointer. | The empty explorer wasn’t listening to the tree it would have shown. |
All of these are fixed in 1.34.2. The two scrollbar fixes work the same way: after layout, the view compares the sizes it drew from with the real ones, and redraws once if they differ.
What I changed about how I check this
The typing lag, the idle redraw and both scrollbar bugs now have tests that fail without the fix. The idle test opens the whole app window, lets five seconds of simulated time pass, and requires that the tab strip and status bar are not rebuilt at all. A second test checks the other direction: a frame that skips those rows gets exactly one refresh within a fifth of a second, and then nothing.
The focus, title-bar and Azure fixes don’t have their own tests yet. I checked them by reading the code paths, not by a test that would catch a regression.
The lesson I take from this is narrow. A cache that depends on every writer announcing its changes needs every writer checked, and “it looked fine when I clicked around” doesn’t find a 100 ms delay. I measured the scroll carefully and the typing not at all.
Getting the fix
1.34.2 has all of the above. The scroll savings from the first post are still there; none of these fixes turn the caches off. If something in the window still shows late or needs a mouse move to appear, tell me from Help › Send Feedback and say what you did just before.