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

Stop committing the whole buffer when determining if it's empty #15582

Merged
merged 5 commits into from
Jun 21, 2023

Conversation

DHowett
Copy link
Member

@DHowett DHowett commented Jun 20, 2023

As a shortcut, GetLastNonSpaceCharacter can start with the last committed row. It's guaranteed that there isn't anything of worth below that point, so why bother checking?

Without this, Terminal immediately commits the entire 9031-line buffer on startup while trying to--get this!--clear the screen!

As a shortcut, GetLastNonSpaceCharacter can start with the last
committed row. It's guaranteed that there isn't anything of worth below
that point, so why bother checking?

Without this, Terminal immediately commits the entire 9031-line buffer
on startup while trying to -- get this -- clear the screen!
Comment on lines 180 to 181
const auto lastRowOffset = static_cast<ptrdiff_t>((_commitWatermark - 1) - _buffer.get()) / _bufferRowStride;
return gsl::narrow_cast<size_t>(lastRowOffset);
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 almost certainly blew up the x86 or audit builds and just haven't bothered to run locally. keep in mind.

@DHowett DHowett requested a review from lhecker June 20, 2023 19:19
src/buffer/out/textBuffer.cpp Outdated Show resolved Hide resolved
src/buffer/out/textBuffer.cpp Outdated Show resolved Hide resolved
// * scratchpad row at offset 0, whereas regular rows start at offset 1.
// * fact that _commitWatermark points _past_ the last committed row,
// but we want to return an index pointing at the last row.
return std::max(0, gsl::narrow_cast<til::CoordType>(lastRowOffset - 2));
Copy link
Member

Choose a reason for hiding this comment

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

I realized that the

const auto y = (_commitWatermark - _buffer.get() - 1) / _bufferRowStride;

calculation is effectively the same as

const auto x = (_commitWatermark - _buffer.get()) / _bufferRowStride;
const auto y = x - 1;

and so it kind of merges with the other -1 we already had to form -2.
I also felt like it's neat because now it's only 2 lines of code and the std::max ensures it's impossible to return negative indices.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmmmm I agree with you, but I probably should have been the one to commit the suggestion ;)

Copy link
Member

Choose a reason for hiding this comment

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

Ah sorry, I thought this would take some load off your shoulders.

@@ -2622,7 +2635,7 @@ HRESULT TextBuffer::Reflow(TextBuffer& oldBuffer,
// printable char gets reset. See GH #12567
auto newRowY = newCursor.GetPosition().y + 1;
const auto newHeight = newBuffer.GetSize().Height();
const auto oldHeight = oldBuffer.GetSize().Height();
const auto oldHeight = oldBuffer._estimateOffsetOfLastCommittedRow() + 1;
Copy link
Member

Choose a reason for hiding this comment

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

I added this, because it's a simple change, but speeds up reflow of empty buffers quite a lot. It needs +1 because _estimateOffsetOfLastCommittedRow returns the offset of the last row and not the height (= past the end) of the buffer.

@DHowett DHowett changed the title Avoid committing the entire buffer when figuring out if it's empty Stop committing the whole buffer when determining if it's empty Jun 21, 2023
@DHowett DHowett enabled auto-merge (squash) June 21, 2023 16:49
@DHowett DHowett merged commit a46a271 into main Jun 21, 2023
@DHowett DHowett deleted the dev/duhowett/less_commit_more_remit branch June 21, 2023 20:52
qqkookie pushed a commit to qqkookie/terminal that referenced this pull request Jun 22, 2023
…osoft#15582)

As a shortcut, GetLastNonSpaceCharacter can start with the last
committed row. It's guaranteed that there isn't anything of worth below
that point, so why bother checking?

Without this, Terminal immediately commits the entire 9031-line buffer
on startup while trying to--get this!--clear the screen!

---------

Co-authored-by: Leonard Hecker <lhecker@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants