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

Improve responsiveness of conhost/ConPTY for large inputs #11890

Merged
merged 6 commits into from Jan 14, 2022

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Dec 7, 2021

This commit replaces the console lock was replaced with a fair ticket
lock implementation, as only fair locks guarantee us that the renderer
(or other parts) can acquire the lock, once the VT parser has finally
released it.

This is related to #11794.

Validation Steps Performed

  • No obvious crashes ✅
  • No text/VT performance regression ✅
  • Cursor blinker starts/stops on focus/defocus of the window ✅

@ghost ghost added Area-Performance Performance-related issue Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Conhost For issues in the Console codebase labels Dec 7, 2021
src/host/_stream.cpp Outdated Show resolved Hide resolved
// But I'm not too concerned that this will lead to issues at the time of writing,
// as CursorBlinker is allocated as a static variable through the Globals class.
// It'd be nice to fix this, but realistically it'll likely not lead to issues.
gci.LockConsole();
Copy link
Member Author

Choose a reason for hiding this comment

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

There's no TryLockConsole() anymore, so I replaced it with a worse solution. 😅
Using the new thread pool API we can simply tell the OS to not block us on exit. It's simpler so that's a win at least.

Copy link
Member

Choose a reason for hiding this comment

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

This was really the only reason that TryLockConsole existed in the first place? Wow.

src/host/CursorBlinker.cpp Outdated Show resolved Hide resolved
src/host/consoleInformation.cpp Outdated Show resolved Hide resolved
src/host/_stream.cpp Outdated Show resolved Hide resolved
Comment on lines +51 to +52
static thread_local ULONG recursionCount = 0;
static til::ticket_lock lock;
Copy link
Member Author

@lhecker lhecker Dec 8, 2021

Choose a reason for hiding this comment

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

Ah btw: You can't have thread locals as class members. They only work as statics / in the global scope.

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.

I'm good with this. Thanks for figuring it out, Leonard.

LOG_LAST_ERROR_IF(!bRet);
}
const auto periodInMS = _uCaretBlinkTime == -1 ? dwDefTimeout : _uCaretBlinkTime;
// The FILETIME struct measures time in 100ns steps. 1ms is 10000ns.
Copy link
Member

Choose a reason for hiding this comment

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

You mean 10000 * 100ns = 1ms, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah exactly. I'll correct it to say "10000 steps" instead.

src/host/consoleInformation.cpp Show resolved Hide resolved
// But I'm not too concerned that this will lead to issues at the time of writing,
// as CursorBlinker is allocated as a static variable through the Globals class.
// It'd be nice to fix this, but realistically it'll likely not lead to issues.
gci.LockConsole();
Copy link
Member

Choose a reason for hiding this comment

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

This was really the only reason that TryLockConsole existed in the first place? Wow.

src/host/consoleInformation.cpp Show resolved Hide resolved
@miniksa miniksa added the Needs-Second It's a PR that needs another sign-off label Jan 12, 2022
Copy link
Member

@carlos-zamora carlos-zamora left a comment

Choose a reason for hiding this comment

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

Huh, this is actually a lot less scary of a change than I thought it would be haha

@DHowett
Copy link
Member

DHowett commented Jan 14, 2022

Admin merge - this predates the splitting out of the "Test" phase

@DHowett DHowett merged commit 7061c54 into main Jan 14, 2022
@DHowett DHowett deleted the dev/lhecker/issue-11794-stuttering branch January 14, 2022 22:57
@ghost
Copy link

ghost commented Feb 3, 2022

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

Handy links:

@lonnywong
Copy link
Contributor

@lhecker I have a question. Is the small input chunks may slow down the input speed? Can we seperate the input and output? #13594

@lhecker
Copy link
Member Author

lhecker commented Nov 14, 2023

This PR is unrelated to your issue as far as I know. I believe the input slowness is caused by the poor architecture inside conhost. If you ever want to improve it, you're absolutely welcome to submit PRs that improve our performance. It's probably easiest to find such performance issues using WPR (Windows Performance Recorder) and WPA (Windows Performance Analyzer). I'm also working on improving its performance but I'm just one person and conhost is ~500k LOC, many parts of which need similar improvements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Performance Performance-related issue Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Second It's a PR that needs another sign-off Priority-1 A description (P1) Product-Conhost For issues in the Console codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants