Summary
::potato::countWindowHeight calls Tk's global update, allowing a geometry/NAWS
measurement to execute unrelated pending UI, input, timer, or socket callbacks.
Working stock patch with latency tester:
https://github.com/potatomushclient/potato/pull/539.patch
Pull request: #539
Why this matters
countWindowHeight is reached from <Configure> through connMaybeNAWS. Calling
update from inside that path processes the complete Tk event queue before the
current handler returns. That permits nested configure handling and can re-enter
socket reads, input dispatch, timers, or other UI work during resize and layout.
This is observable as intermittent UI stalls and creates unsafe event ordering even
when an individual height calculation appears inexpensive.
Stock reproducer
The attached test queues an unrelated zero-delay callback immediately before calling
countWindowHeight:
- Unmodified stock: the callback fires inside
countWindowHeight and the regression
assertion fails.
- Patched stock: the callback remains pending until the normal event loop resumes,
and all assertions pass.
The test also verifies that the function still returns a positive visible row count.
Latency results
Windows, Tcl/Tk 8.6.18, upstream commit
46d18387bd6b156b85176fa588a60991cbba6235:
| Build |
Re-entry assertion |
p50 |
p95 |
max |
| Stock |
FAIL |
0.011 ms |
0.060 ms |
0.600 ms |
| Patched fresh worktree |
PASS |
0.005 ms |
0.006 ms |
0.237 ms |
The primary fix is removal of nested event-loop processing. The focused 500-call
measurement also showed an approximately 90 percent p95 reduction.
Included tester
The patch adds:
tests/Test-WindowHeightLatency.ps1
tests/window-height-latency.test.tcl
Run with:
./tests/Test-WindowHeightLatency.ps1 -Runtime C:/path/to/tclkit-8.6.18-win64-intel-tk.exe
Validation
- Built directly against stock
potatomushclient/potato:master
- Fresh-worktree patch apply check: PASS
- Downloaded GitHub PR
.patch apply check: PASS
- Reverse patch check: PASS
- PowerShell parser: PASS
- Patched Tcl/Tk assertions: PASS
- No split-screen, packet-debugger, telemetry, or other custom-client code
Summary
::potato::countWindowHeightcalls Tk's globalupdate, allowing a geometry/NAWSmeasurement to execute unrelated pending UI, input, timer, or socket callbacks.
Working stock patch with latency tester:
https://github.com/potatomushclient/potato/pull/539.patch
Pull request: #539
Why this matters
countWindowHeightis reached from<Configure>throughconnMaybeNAWS. Callingupdatefrom inside that path processes the complete Tk event queue before thecurrent handler returns. That permits nested configure handling and can re-enter
socket reads, input dispatch, timers, or other UI work during resize and layout.
This is observable as intermittent UI stalls and creates unsafe event ordering even
when an individual height calculation appears inexpensive.
Stock reproducer
The attached test queues an unrelated zero-delay callback immediately before calling
countWindowHeight:countWindowHeightand the regressionassertion fails.
and all assertions pass.
The test also verifies that the function still returns a positive visible row count.
Latency results
Windows, Tcl/Tk 8.6.18, upstream commit
46d18387bd6b156b85176fa588a60991cbba6235:The primary fix is removal of nested event-loop processing. The focused 500-call
measurement also showed an approximately 90 percent p95 reduction.
Included tester
The patch adds:
tests/Test-WindowHeightLatency.ps1tests/window-height-latency.test.tclRun with:
Validation
potatomushclient/potato:master.patchapply check: PASS