Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an efficient text stream write function #14821

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Feb 10, 2023

This adds PR adds a couple foundational functions and classes to make
our TextBuffer more performant and allow us to improve our Unicode
correctness in the future, by getting rid of our dependence on
OutputCellIterator. In the future we can then replace the simple
UTF-16 code point iterator with a proper grapheme cluster iterator.

While my focus is technically on Unicode correctness, the ~4x VT
throughput increase in OpenConsole is pretty nice too.

This PR adds:

  • A new, simpler ROW iterator (unused in this PR)
  • Cursor movement functions (NavigateToPrevious, NavigateToNext)
    They're based on functions that align the cursor to the start/end
    of the current cell, so such functions can be added as well.
  • Write to write a raw string of text with the possibility to
    specify a right margin.
  • WriteWithOffsets will allow us to make reflow much faster,
    as it's able to bulk-copy already measured strings extremely fast
    without re-measuring them.

Related to #8000

Validation Steps Performed

  • enwik8.txt, zhwik8.txt, emoji-test.txt, all work with proper
    wide glyph reflow at the end of a row

@lhecker lhecker marked this pull request as draft February 10, 2023 16:43
@lhecker lhecker added Product-Conhost For issues in the Console codebase Area-Output Related to output processing (inserting text into buffer, retrieving buffer text, etc.) Area-Server Down in the muck of API call servicing, interprocess communication, eventing, etc. Product-Terminal The new Windows Terminal. Issue-Scenario labels Feb 10, 2023
@zadjii-msft
Copy link
Member

me reading this pr body rn

image

@lhecker lhecker force-pushed the dev/lhecker/8000-stream-writing branch from db90593 to 1a24ff3 Compare March 6, 2023 17:09
@github-actions

This comment has been minimized.

@lhecker lhecker force-pushed the dev/lhecker/8000-stream-writing branch from 1a24ff3 to a6c5e7a Compare March 6, 2023 17:15
@lhecker lhecker marked this pull request as ready for review March 6, 2023 17:20
src/terminal/adapter/adaptDispatch.cpp Show resolved Hide resolved
src/terminal/adapter/adaptDispatch.cpp Outdated Show resolved Hide resolved
tools/ConsoleTypes.natvis Outdated Show resolved Hide resolved
@github-actions

This comment has been minimized.

uint16_t column = 0;
for (const auto& ch : std::wstring_view{ L"AB\u304bC\u304dDE " })
{
const uint16_t width = ch >= 0x80 ? 2 : 1;
pRow->ReplaceCharacters(column, width, { &ch, 1 });
column += width;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot why I made this change... But it's much shorter now, so there's that at least.

@@ -65,6 +68,65 @@ constexpr OutIt copy_n_small(InIt first, Diff count, OutIt dest)
return dest;
}

RowTextIterator::RowTextIterator(std::span<const wchar_t> chars, std::span<const uint16_t> charOffsets, uint16_t offset) noexcept :
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RowTextIterator isn't used anywhere yet, but I did use it during development as a debug aid. I expect this struct to be used in the future for things like CHAR_INFO reads.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Output Related to output processing (inserting text into buffer, retrieving buffer text, etc.) Area-Server Down in the muck of API call servicing, interprocess communication, eventing, etc. Issue-Scenario Product-Conhost For issues in the Console codebase Product-Terminal The new Windows Terminal.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants