[PR #15524] Initialize rows lazily #30664

Open
opened 2026-01-31 09:42:10 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/15524

State: closed
Merged: Yes


For a 120x9001 terminal, a01500f reduced the private working set of
conhost by roughly 0.7MB, presumably due to tighter ROW packing, but
also increased it by 2.1MB due to the addition of the _charOffsets
array on each ROW instance. An option to fix this would be to only
allocate a _charOffsets if the first wide or complex Unicode glyph
is encountered. But on one hand this would be quite western-centric
and unfairly hurt most languages that exist and on another we can get
rid of the _charOffsets array entirely in the future by injecting
ZWNJs if a write begins with a combining glyph and just recount each
row from the start. That's still faster than fragmented memory.

This commit goes a different way and instead reduces the working
set of conhost after it launches from 7MB down to just 2MB,
by only committing ROWs when they're first used.

Finally, it adds a "scratchpad" row which can be used to build
more complex contents, for instance to horizontally scroll them.

Validation Steps Performed

  • Traditional resize
    • Horizontal shrinking works
    • Vertical shrinking works and cursor stays in the viewport
  • Reflow works
  • Filling the buffer with ASCII works and no leaks
  • Filling the buffer with complex Unicode works and no leaks
  • ^[[3J erases scrollback
  • Test ScrollRows with a positive delta
  • I don't know how to test Reset. Unit tests use it though
**Original Pull Request:** https://github.com/microsoft/terminal/pull/15524 **State:** closed **Merged:** Yes --- For a 120x9001 terminal, a01500f reduced the private working set of conhost by roughly 0.7MB, presumably due to tighter `ROW` packing, but also increased it by 2.1MB due to the addition of the `_charOffsets` array on each `ROW` instance. An option to fix this would be to only allocate a `_charOffsets` if the first wide or complex Unicode glyph is encountered. But on one hand this would be quite western-centric and unfairly hurt most languages that exist and on another we can get rid of the `_charOffsets` array entirely in the future by injecting ZWNJs if a write begins with a combining glyph and just recount each row from the start. That's still faster than fragmented memory. This commit goes a different way and instead reduces the working set of conhost after it launches from 7MB down to just 2MB, by only committing ROWs when they're first used. Finally, it adds a "scratchpad" row which can be used to build more complex contents, for instance to horizontally scroll them. ## Validation Steps Performed * Traditional resize * Horizontal shrinking works ✅ * Vertical shrinking works ✅ and cursor stays in the viewport ✅ * Reflow works ✅ * Filling the buffer with ASCII works ✅ and no leaks ✅ * Filling the buffer with complex Unicode works ✅ and no leaks ✅ * `^[[3J` erases scrollback ✅ * Test `ScrollRows` with a positive delta ✅ * I don't know how to test `Reset`. ❔ Unit tests use it though
claunia added the pull-request label 2026-01-31 09:42:10 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#30664