terminal/src
Austin Lamb 539a5dc0af
Greatly reduce allocations in the conhost/OpenConsole startup path (#8489)
I was looking at conhost/OpenConsole and noticed it was being pretty
inefficient with allocations due to some usages of std::deque and
std::vector that didn't need to be done quite that way.

So this uses std::vector for the TextBuffer's storage of ROW objects,
which allows one allocation to contiguously reserve space for all the
ROWs - on Desktop this is 9001 ROW objects which means it saves 9000
allocations that the std::deque would have done.  Plus it has the
benefit of increasing locality of the ROW objects since deque is going
to chase pointers more often with its data structure.

Then, within each ROW there are CharRow and ATTR_ROW objects that use
std::vector today.  This changes them to use Boost's small_vector, which
is a variation of vector that allows for the so-called "small string
optimization."  Since we know the typical size of these vectors, we can
pre-reserve the right number of elements directly in the
CharRow/ATTR_ROW instances, avoiding any heap allocations at all for
constructing these objects.

There are a ton of variations on this "small_vector" concept out there
in the world - this one in Boost, LLVM has one called SmallVector,
Electronic Arts' STL has a small_vector, Facebook's folly library has
one...there are a silly number of these out there.  But Boost seems like
it's by far the easiest to consume in terms of integration into this
repo, the CI/CD pipeline, licensing, and stuff like that, so I went with
the boost version.

In terms of numbers, I measured the startup path of OpenConsole.exe on
my dev box for Release x64 configuration.  My box is an i7-6700k @ 4
Ghz, with 32 GB RAM, not that I think machine config matters much here:

|        | Allocation count    | Allocated bytes    | CPU usage (ms) |
| ------ | ------------------- | ------------------ | -------------- |
| Before | 29,461              | 4,984,640          | 103            |
| After  | 2,459 (-91%)        | 4,853,931 (-2.6%)  | 96 (-7%)       |

Along the way, I also fixed a dynamic initializer I happened to spot in
the registry code, and updated some docs.

## Validation Steps Performed
- Ran "runut", "runft" and "runuia" locally and confirmed results are
  the same as the main branch
- Profiled the before/after numbers in the Visual Studio profiler, for
  the numbers shown in the table

Co-authored-by: Austin Lamb <austinl@microsoft.com>
2020-12-16 10:40:30 -08:00
..
buffer Greatly reduce allocations in the conhost/OpenConsole startup path (#8489) 2020-12-16 10:40:30 -08:00
cascadia Greatly reduce allocations in the conhost/OpenConsole startup path (#8489) 2020-12-16 10:40:30 -08:00
dep Move all wildcards into targets or expand them (#6406) 2020-06-08 14:01:47 -07:00
host Greatly reduce allocations in the conhost/OpenConsole startup path (#8489) 2020-12-16 10:40:30 -08:00
inc Add support for autodetecting URLs and making hyperlinks (#7691) 2020-10-28 20:24:43 +00:00
interactivity Fix the xterm and SGR mouse encodings for CTRL, ALT, SHIFT (#8379) 2020-11-30 03:45:53 +00:00
internal Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
propsheet Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
propslib Greatly reduce allocations in the conhost/OpenConsole startup path (#8489) 2020-12-16 10:40:30 -08:00
renderer Implement user-specified pixel shaders, redux (#8565) 2020-12-15 20:40:22 +00:00
server Convert DeviceComm into an interface and add handle exchange (#8367) 2020-12-15 23:07:43 +00:00
terminal Refactor DEC/ANSI modes to avoid duplication when we add SM/RM (#8469) 2020-12-03 21:51:59 +00:00
testlist inbox: Merge accumulated build fixes from RS_ONECORE_DEP_ACIOSS (#1002) 2019-05-24 12:28:30 -07:00
til Add support for autodetecting URLs and making hyperlinks (#7691) 2020-10-28 20:24:43 +00:00
tools Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
tsf Change backslashes in include statements to forward slashes (#8205) 2020-11-25 21:02:10 +00:00
types Fix SA for Visual Studio 16.8 (#8551) 2020-12-11 05:04:30 +00:00
winconpty conpty: fall back to conhost if OpenConsole is missing (#7741) 2020-10-15 11:50:27 -07:00
common.build.post.props Move CI and audit build to the WinDev scale set pool (#8080) 2020-10-28 20:49:13 +00:00
common.build.pre.props Greatly reduce allocations in the conhost/OpenConsole startup path (#8489) 2020-12-16 10:40:30 -08:00
common.build.tests.props Update TAEF to 10.57.200731005-develop (#7164) 2020-08-03 20:47:02 +00:00
ConsolePerf.regions.xml Tab to spaces (#578) 2019-05-13 18:06:36 -07:00
ConsolePerf.wprp Fix the WPR profile (#4007) 2019-12-17 17:14:15 -08:00
cppwinrt.build.post.props Remove all our path antics; force native projects to bin/, obj/ (#8062) 2020-10-27 15:00:41 -07:00
cppwinrt.build.pre.props Fix the WINRT_NO_MAKE_DETECTION build break (#8067) 2020-10-27 17:56:09 -07:00
dirs build: move oss required to build conhost out of dep/ (#5451) 2020-04-21 14:43:09 -07:00
project.inc Merged PR 5425054: [Git2Git] conhost: explicitly set /utf-8 on the compiler commandline 2020-11-19 23:25:34 +00:00
project.unittest.inc Merged PR 4915530: Reflect OS Build fixes on top of 58f5d7c7 2020-07-13 23:00:53 +00:00
StaticAnalysis.ruleset Fix SA for Visual Studio 16.8 (#8551) 2020-12-11 05:04:30 +00:00
unit.tests.x64.runsettings Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
unit.tests.x86.runsettings Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
wap-common.build.post.props Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00
wap-common.build.pre.props Initial release of the Windows Terminal source code 2019-05-02 15:29:04 -07:00