Skip to content

Commit

Permalink
Hold a conversion buffer string on the VtEngine to prevent hundreds o…
Browse files Browse the repository at this point in the history
…f thousands of transient allocations as we convert things to emit them as a UTF-8 string.
  • Loading branch information
miniksa committed Jan 8, 2021
1 parent 00f80e4 commit d8cbaed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/renderer/vt/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ VtEngine::VtEngine(_In_ wil::unique_hfile pipe,
_deferredCursorPos{ INVALID_COORDS },
_inResizeRequest{ false },
_trace{},
_bufferLine{}
_bufferLine{},
_buffer{},
_formatBuffer{},
_conversionBuffer{}
{
#ifndef UNIT_TESTING
// When unit testing, we can instantiate a VtEngine without a pipe.
Expand Down Expand Up @@ -146,8 +149,11 @@ VtEngine::VtEngine(_In_ wil::unique_hfile pipe,
{
try
{
const auto converted = ConvertToA(CP_UTF8, wstr);
return _Write(converted);
// We're likely going to be converting a ton of strings, so we'll use
// a buffer string stored on this class so we don't end up alloc/freeing
// in a tight loop and wasting a bunch of time and energy on that.
ConvertToA(CP_UTF8, wstr, _conversionBuffer);
return _Write(_conversionBuffer);
}
CATCH_RETURN();
}
Expand Down
1 change: 1 addition & 0 deletions src/renderer/vt/vtrenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ namespace Microsoft::Console::Render
std::string _buffer;

std::string _formatBuffer;
std::string _conversionBuffer;

TextAttribute _lastTextAttributes;

Expand Down

0 comments on commit d8cbaed

Please sign in to comment.