[GH-ISSUE #7640] perf: selection lorebook button forces a layout on every app scroll #4226

Closed
opened 2026-10-21 06:12:50 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @Gunterlie on GitHub (Oct 14, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/7640

Originally assigned to: @Gunterlie, @SpicyMarinara on GitHub.

Problem

SelectionLorebookButton (the "selected chat text → lorebook entry" button, #6899) adds a capture scroll listener on window and a resize listener. Each event schedules readMessageSelection() for the next frame, and window.getSelection() there forces a style and layout update.

The capture listener hears every scroller in the app, not only the chat. A package screen that scrolls while a chat is mounted behind it pays a forced layout on every frame, even with no text selected.

Evidence

Measured on a production install with headless Chromium at 390×844 and 4× CPU throttle while scrolling Slurp's Discover screen (a package screen over the chat). The function (Qm in the ChatArea chunk) had 592 ms of self time while Discover opened and 109 ms during a 40-frame scroll.

Proposed fix

Scroll and resize events schedule the selection read only while a non-collapsed selection exists. selectionchange still updates the button as before.

Originally created by @Gunterlie on GitHub (Oct 14, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/7640 Originally assigned to: @Gunterlie, @SpicyMarinara on GitHub. ## Problem `SelectionLorebookButton` (the "selected chat text → lorebook entry" button, #6899) adds a capture `scroll` listener on `window` and a `resize` listener. Each event schedules `readMessageSelection()` for the next frame, and `window.getSelection()` there forces a style and layout update. The capture listener hears every scroller in the app, not only the chat. A package screen that scrolls while a chat is mounted behind it pays a forced layout on every frame, even with no text selected. ## Evidence Measured on a production install with headless Chromium at 390×844 and 4× CPU throttle while scrolling Slurp's Discover screen (a package screen over the chat). The function (`Qm` in the `ChatArea` chunk) had 592 ms of self time while Discover opened and 109 ms during a 40-frame scroll. ## Proposed fix Scroll and resize events schedule the selection read only while a non-collapsed selection exists. `selectionchange` still updates the button as before.
bsakaguchi 2026-10-21 06:12:50 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#4226
No description provided.