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

Throttle cursor redrawing in outputStream.cpp #10394

Merged
3 commits merged into from
Jun 28, 2021

Conversation

skyline75489
Copy link
Collaborator

@skyline75489 skyline75489 commented Jun 10, 2021

Try to throttle the cursor redrawing in the conhost world.

The motivation of this is the high CPU usage of TriggerRedrawCursor (#10393).

This can be seen as the conhost version of #2960.

This saves 5%~8% of the CPU time.

Supports #10462.

@skyline75489
Copy link
Collaborator Author

I know conhost code are in maintenance mode so I'm marking this as a draft.

This should help both conhost & WT (OpenConsole).

@@ -76,8 +76,13 @@ void WriteBuffer::_DefaultStringCase(const std::wstring_view string)
{
size_t dwNumBytes = string.size() * sizeof(wchar_t);

_io.GetActiveOutputBuffer().GetTextBuffer().GetCursor().SetIsOn(true);
Cursor& cursor = _io.GetActiveOutputBuffer().GetTextBuffer().GetCursor();
if (!cursor.IsOn())
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here SetIsOn() calls RedrawCursorAlways() and causes unnecessary overhead.

I feel this one is safe, since we deliberately want the cursor to be on and visible.


//cursor.StartDeferDrawing();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm no sure if this is a safe change, though.

This reduces the unnecessary cursor redrawing caused by WriteCharsLegacy where a lot of cursor position adjustment happens.

Copy link
Member

Choose a reason for hiding this comment

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

Why wouldn't this be a safe change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

TBH it's because I'm afraid of WriteCharsLegacy, one of the most easy-to-break piece of code in conhost.

Copy link
Member

Choose a reason for hiding this comment

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

No, do it. Please. It honestly was deferred like 7 years ago and I think I screwed it up and it's how I've been grinding out "cursor turds" bugs ever since. And if I'm wrong.... well it won't be the first or last time.

@skyline75489 skyline75489 changed the title Throttle cursor redrawing in outputStream.cpp [DRAFT] Throttle cursor redrawing in outputStream.cpp Jun 15, 2021
@skyline75489
Copy link
Collaborator Author

I see no obvious cursor rendering issue after this. So I'm marking this ready for review.

@skyline75489 skyline75489 marked this pull request as ready for review June 18, 2021 09:19
@skyline75489 skyline75489 changed the title [DRAFT] Throttle cursor redrawing in outputStream.cpp Throttle cursor redrawing in outputStream.cpp Jun 18, 2021
Copy link
Member

@miniksa miniksa left a comment

Choose a reason for hiding this comment

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

Welp, may as well give it a try.

@DHowett DHowett added the AutoMerge Marked for automatic merge by the bot when requirements are met label Jun 28, 2021
@ghost
Copy link

ghost commented Jun 28, 2021

Hello @DHowett!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit 4fc283f into microsoft:main Jun 28, 2021
Cursor& cursor = _io.GetActiveOutputBuffer().GetTextBuffer().GetCursor();
if (!cursor.IsOn())
{
cursor.SetIsOn(true);
Copy link
Member

Choose a reason for hiding this comment

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

I am surprised that Cursor does not ignore an "on->on" transition itself

@ghost
Copy link

ghost commented Jul 14, 2021

🎉Windows Terminal Preview v1.10.1933.0 has been released which incorporates this pull request.:tada:

Handy links:

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AutoMerge Marked for automatic merge by the bot when requirements are met
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants