Repository navigation
perf(readline): optimize per-keystroke rendering and completion latency - #32
Merged
caomengxuan666 merged 2 commits intoMar 20, 2026
Merged
Conversation
- Add completions_dirty flag: recompute completions only when buffer changes (insert, backspace, tab, history nav), not on every event - Avoid double UTF-8 conversion in redraw(): convert buffer to wstring once and reuse in both step 3 (render) and step 5 (cursor restore); use MultiByteToWideChar() to compute wchar cursor offset in-place - Replace FillConsoleOutputAttribute + WriteConsoleOutputCharacterW with a single WriteConsoleOutputW call in writeAt(), halving Win32 syscalls for each completion row drawn - Replace per-char while-loop padding with wstring::append(n, L' ') and add reserve(W) to avoid reallocation when building each row
…fallback - add REPL sudo rewrite: `sudo <builtin> ...` -> `sudo "<winuxcmd.exe>" <builtin> ...` - ensure Windows native sudo can elevate and execute WinuxCmd built-ins (e.g. lsof) - route shell meta commands (`|`, `>`, `<`, `&`) to native fallback in REPL - keep direct built-in dispatch for normal single commands unchanged
Member
Author
|
Fix Windows sudo compatibility for WinuxCmd built-ins in REPL SummaryThis PR fixes a Windows-specific REPL issue where Root CauseIn REPL mode, built-in commands are dispatched internally and do not necessarily exist as standalone executables ( Changes
Behavior After
Verification
|
caomengxuan666
added a commit
that referenced
this pull request
Mar 24, 2026
…l-integration perf(readline): optimize per-keystroke rendering and completion latency
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reduces unnecessary computation and Win32 API calls on every key event
in the interactive readline loop.
Changes
1. Lazy completion recomputation (
completions_dirtyflag)Previously
completer(buffer)was called unconditionally at the top ofthe event loop, even for arrow keys, Escape, or any event that does not
modify the buffer. A
completions_dirtyboolean now gates the call —completions are recomputed only when the buffer actually changes
(character insert, Backspace, Tab accept, history navigation).
2. Remove duplicate UTF-8 → wstring conversion in
redraw()utf8_to_wstring(buffer)was called twice per redraw: once to renderthe buffer text (step 3) and again to render the cursor position (step 5
via a
substrcopy). The wstring is now produced once and hoisted tothe enclosing scope. Cursor wchar-offset is computed with a zero-copy
MultiByteToWideChar(..., nullptr, 0)dry-run, eliminating a heapallocation on every redraw.
3. Single syscall for completion row rendering (
writeAt)The old implementation issued two separate Win32 calls per row:
FillConsoleOutputAttributethenWriteConsoleOutputCharacterW.Replaced with a single
WriteConsoleOutputWover a stack-allocatedCHAR_INFObuffer, combining character and attribute writes. With upto 8 visible completion rows this halves the per-frame syscall count
for the popup.
4. Efficient string padding for completion rows
The per-character
while (size < CMD_COLUMN_WIDTH) line += L' 'loopis replaced with
line.append(n, L' ').line.reserve(W)is addedupfront to avoid repeated reallocation during row construction.
Testing
devpreset (no errors, no new warnings).unchanged; only the rendering path is affected.