Fix PostEvent races, event buffer growth, and Text::Select cost - #1313
Merged
Conversation
PostEvent pushed into the unsynchronized event buffer, racing with the main loop when called from another thread. Route it through the mutex-protected task queue instead.
The setup receiver outlived setup with a frozen index, pinning every subsequent event in the buffer for the App lifetime. Scope it to InstallTerminalInfo.
Select allocated one entry per line of the whole text and scanned from line 0 on every frame while a selection is active. Store only the selection/box intersection. 100k lines: 0.41ms -> 0.011ms per frame.
ArthurSonzogni
force-pushed
the
fix/event-loop-bugs
branch
from
July 20, 2026 07:43
96765ad to
1556675
Compare
|
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.
Three independent fixes, one commit each.
App::PostEventthread safety. Documented as thread safe, but since the 7.0 event loop rework it pushed into the unsynchronized event buffer, racing with the main loop draining it. Now routed through the mutex-protected task queue;HandleTaskalready handles the Event variant identically. New test posts 10k events from another thread.Unbounded event buffer growth. The setup receiver outlived setup with a frozen index.
MultiReceiverBuffer::Prune()only frees below the minimum receiver index, so every subsequent event — including every mouse move — was retained for the App lifetime. The receiver is now scoped toInstallTerminalInfo.Text::Selectcost on large texts. It allocated one row entry per line of the whole text and scanned from line 0, every frame while a selection is active — defeating the #1309 optimization (~16MB allocated per frame on a million-line text). It now visits only the selection/box intersection. 100k lines with an active selection: 0.41ms → 0.011ms per frame. Also adds the first selection test for a multi-linetext().Note: trivial conflict with #1310 on
PostEvent; the resolution is this branch's version (Post(Task(...))).