terminal/src/cascadia
Michael Niksa 525be22bd8
Eliminate more transient allocations: Titles and invalid rectangles and bitmap runs and utf8 conversions (#8621)
## References
* See also #8617 

## PR Checklist
* [x] Supports #3075
* [x] I work here.
* [x] Manual test.

## Detailed Description of the Pull Request / Additional comments

### Window Title Generation
Every time the renderer checks the title, it's doing two bad things that
I've fixed:
1. It's assembling the prefix to the full title doing a concatenation.
   No one ever gets just the prefix ever after it is set besides the
   concat. So instead of storing prefix and the title, I store the
   assembled prefix + title and the bare title.
2. A copy must be made because it was returning `std::wstring` instead
   of `std::wstring&`. Now it returns the ref.

### Dirty Area Return
Every time the renderer checks the dirty area, which is sometimes
multiple times per pass (regular text printing, again for selection,
etc.), a vector is created off the heap to return the rectangles. The
consumers only ever iterate this data. Now we return a span over a
rectangle or rectangles that the engine must store itself.
1. For some renderers, it's always a constant 1 element. They update
   that 1 element when dirty is queried and return it in the span with a
   span size of 1.
2. For other renderers with more complex behavior, they're already
   holding a cached vector of rectangles. Now it's effectively giving
   out the ref to those in the span for iteration.

### Bitmap Runs
The `til::bitmap` used a `std::optional<std::vector<til::rectangle>>`
inside itself to cache its runs and would clear the optional when the
runs became invalidated. Unfortunately doing `.reset()` to clear the
optional will destroy the underlying vector and have it release its
memory. We know it's about to get reallocated again, so we're just going
to make it a `std::pmr::vector` and give it a memory pool. 

The alternative solution here was to use a `bool` and
`std::vector<til::rectangle>` and just flag when the vector was invalid,
but that was honestly more code changes and I love excuses to try out
PMR now.

Also, instead of returning the ref to the vector... I'm just returning a
span now. Everyone just iterates it anyway, may as well not share the
implementation detail.

### UTF-8 conversions
When testing with Terminal and looking at the `conhost.exe`'s PTY
renderer, it spends a TON of allocation time on converting all the
UTF-16 stuff inside to UTF-8 before it sends it out the PTY. This was
because `ConvertToA` was allocating a string inside itself and returning
it just to have it freed after printing and looping back around again...
as a PTY does.

The change here is to use `til::u16u8` that accepts a buffer out
parameter so the caller can just hold onto it.

## Validation Steps Performed
- [x] `big.txt` in conhost.exe (GDI renderer)
- [x] `big.txt` in Terminal (DX, PTY renderer)
- [x] Ensure WDDM and BGFX build under Razzle with this change.
2021-02-16 20:52:33 +00:00
..
CascadiaPackage Remove accidental System.Core.dll from CascadiaPackage (#9153) 2021-02-16 12:01:14 +00:00
inc Polish the Background Image settings (#8778) 2021-01-18 22:34:07 +00:00
LocalTests_SettingsModel Bugfix: update color scheme references properly (#9103) 2021-02-10 22:11:56 +00:00
LocalTests_TerminalApp Separate runtime TerminalSettings from profile-TerminalSettings (#8602) 2021-02-08 22:01:40 +00:00
PublicTerminalCore Exclude more rarely-used stuff from Windows headers (#8513) 2020-12-11 19:35:23 +00:00
Remoting Add support for running a commandline in another WT window (#8898) 2021-02-10 11:28:09 +00:00
ShellExtension Fix crash in explorer background context menu logic (#8977) 2021-02-01 17:30:54 +00:00
TerminalApp Add Keyboard Navigation To Color Picker (#9144) 2021-02-16 17:36:34 +00:00
TerminalAzBridge Exclude more rarely-used stuff from Windows headers (#8513) 2020-12-11 19:35:23 +00:00
TerminalConnection make "open terminal here" context menu work for directory background (#8638) 2021-01-06 19:59:30 +00:00
TerminalControl Prevent read-only warning on mouse move, wheel and release (#9107) 2021-02-11 15:16:36 +00:00
TerminalCore Eliminate more transient allocations: Titles and invalid rectangles and bitmap runs and utf8 conversions (#8621) 2021-02-16 20:52:33 +00:00
TerminalSettingsEditor Add support for "focus follows mouse" mode (#8965) 2021-02-09 22:18:20 +00:00
TerminalSettingsModel Bugfix: update color scheme references properly (#9103) 2021-02-10 22:11:56 +00:00
UnitTests_Remoting Add support for running a commandline in another WT window (#8898) 2021-02-10 11:28:09 +00:00
UnitTests_TerminalCore Add support for "focus follows mouse" mode (#8965) 2021-02-09 22:18:20 +00:00
ut_app Update to Microsoft.UI.Xaml 2.5 "stable" (#8500) 2020-12-04 23:49:45 +00:00
WindowsTerminal Add support for running a commandline in another WT window (#8898) 2021-02-10 11:28:09 +00:00
WindowsTerminalUniversal Update Win32 Toolkit (6.1.2) and VCRT Forwarders (1.0.4) (#8501) 2020-12-10 01:30:00 +00:00
WinRTUtils Exclude more rarely-used stuff from Windows headers (#8513) 2020-12-11 19:35:23 +00:00
WpfTerminalControl wpf: Add a TerminalControlSize emptiness check (#8906) 2021-01-26 13:57:30 -08:00
WpfTerminalTestNetCore wpf: target netcoreapp3.1, clean up test project path (#8491) 2020-12-04 18:17:25 +00:00
wt Build and ship an actual binary named wt that just launches WT (#6860) 2020-07-10 22:41:37 +00:00
CascadiaResources.build.items Introduce TerminalSettingsModel project (#7667) 2020-10-06 09:56:59 -07:00