You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Performance of System.Console.CursorLeft and System.Console.CursorTop is really, really bad in .NET Core 2.1.2 on Linux #27034
I am trying to use this library as a progress bar for a netcoreapp2.1 console app on Linux. However, I found that since it uses System.Console.CursorLeft and System.Console.CursorTop frequently (in loops), that it was completely unusable. If you click on the link, there are some GIFs in the README that show the demo program completing in about 15-20 seconds. I let the demo program run on .NET Core 2.1.2 on Linux for 12 hours!!! and it was still on 0%. I did some profiling on this and found that 50% of the CPU time was in system calls to the kernel reading and writing stdin.
@dlech we are considering re-writing our protocol for getting cursor position in vNext of .Net Core, we'll keep this issue in mind when designing/testing our solution.
this seems so extreme that surely it can be improved somewhat
Do you have suggestions? We get the cursor position by writing a sequence to the terminal, and then reading and parsing a response from the terminal. That's all inherently slow. The only faster solution I'm aware of is keeping track of what we think the current position is, but that's very fragile.
My memory is getting kind of fuzzy, but I think this was working reasonably well in dotnet 1.x (program took minutes instead of days). So maybe look at the changes between 1.x and 2.x?
I did some profiling in dotnet 2.x. If I recall correctly, there were problems with lock contention that were the biggest slowdown in dotnet 2.0, but those were fixed in dotnet 2.1. I don't remember which ones exactly, but it seems like dotnet 2.1.2 was spending most of its time in Linux system calls. If I get a chance, I might try profiling again with dotnet 2.1.3 and see if it makes any difference.
@stephentoub just curious what you mean by the fragility? Issue 489 has been linked to this issue, and we'd planned on releasing the RTM of the tool with .NET Core 2.2, but we're going to ship it as a preview given the degraded experience for Ubuntu users and hope to have a fix in place in time for us to RTM (or fully release) the tools in the 3.0 time frame.
I'd like to understand the fragility the fix would cause - we definitely don't want to ask that a "fragile fix" get shipped, but we do want to improve the experience for our Ubuntu users. I'd also like to understand the solution @wtgodbe mentioned above, in which the cursor position protocol might be tweaked. Is there a time frame for this or is it a non-viable solution to this issue?
I meant that such an approach would require the System.Console implementation to always have a perfect mirror of exactly where the cursor is. That means it needs to know and be able to hook / react to everything that could possibly move the cursor, including various key strokes, mouse clicks and drags, window resizing, window scrolling, etc., plus such actions hooked by child processes launched by it, etc. I expect it can be done, but the fragility comes from having confidence that we've done it 100% correct. If we miss something, then the System.Console knowledge of where the cursor is could be very out of sync from where it actually is.
in which the cursor position protocol might be tweaked
I'm not sure what @wtgodbe was referring to. Will?
@dlech - thanks for verifying the performance is consistent with 1.1.10. that's helpful.
@richlander - this is an interesting consideration.
off the top of my head just imagining visualizing OAI endpoints like this is interesting, but i'm not entirely sure i grok what you're envisioning. mind a sync with @stephentoub and/or @wtgodbe and myself to noodle some ideas friday or next week?
@bradygaster I wasn't suggesting emulating the exact top UX. Instead, I was making the point that top writes dynamic data to the console at arbitrary x,y coordinates and has a certain performance profile. Is that super general UX close to what you want?
Look for something else that does what you want and figure out if it has a model we can emulate in some way. The challenge might be that top can do what it does because it is a constrained app with constrained user input. @stephentoub is likely making the point that we don't have the luxury of a constrained environment. That said, if your app is more like top, then maybe you can rely on your own console implementation that doesn't have to make the same generic reliability guarantees as System.Console.
Got it @richlander. Appreciate the clarification. I'm going to tinker around with top more, and also aggressively experiment with the httprepl to see what I'd want as a user from the experience. I've synced up with @mlorbetske on this briefly, too, to get his ideas on the thread, specifically on this:
maybe you can rely on your own console implementation that doesn't have to make the same generic reliability guarantees as System.Console
The change that we were considering is essentially what @stephentoub described - that is, maintaining our own understanding of where the cursor is at all times. As he said, though, that can be very tricky to get correct (and difficult to know that we've gotten it correct). @bradygaster if you'd like to chat with Stephen & I next week I'd be happy to do so
Ubuntu 18.0.4(*) broke global tools because the CurrentCulture changed to en-US-POSIX. Thus code like the following doesn't do what is expected - this code returns false:
I could imagine complicating scenarios where something similar raised exceptions, causing exceptions to slow things down and cause general chaos.
This wound up in (the beautifully binary issue number) CLI Issue 10101. It was an easy fix for us, because we should have been using InvariantCulture anyway (oops) - so we just removed all use of CurrentCulture in global tools.
(*) We did not confirm that this is restricted to 18.0.4, it is just where we had it reported and it feels plausible that this is a change in or near 18.0.4
Ubuntu 18.0.4(*) broke global tools because the CurrentCulture changed to en-US-POSIX
Just to be clear, CurrentCulture ends up respecting whatever environment is set via environment variables like LANG, and apparently Ubuntu (or the images of it we're using?) is now defaulting to something far from ideal.
cc: @tarekgh
Activity
dlech commentedon Jul 31, 2018
I made my own GIF so you can see just how slow it is in comparison. 😄
wtgodbe commentedon Sep 14, 2018
@karelz @stephentoub this seems potentially related to https://github.com/dotnet/corefx/issues/30406 & friends.
@dlech we are considering re-writing our protocol for getting cursor position in vNext of .Net Core, we'll keep this issue in mind when designing/testing our solution.
stephentoub commentedon Sep 24, 2018
Do you have suggestions? We get the cursor position by writing a sequence to the terminal, and then reading and parsing a response from the terminal. That's all inherently slow. The only faster solution I'm aware of is keeping track of what we think the current position is, but that's very fragile.
dlech commentedon Sep 24, 2018
My memory is getting kind of fuzzy, but I think this was working reasonably well in dotnet 1.x (program took minutes instead of days). So maybe look at the changes between 1.x and 2.x?
I did some profiling in dotnet 2.x. If I recall correctly, there were problems with lock contention that were the biggest slowdown in dotnet 2.0, but those were fixed in dotnet 2.1. I don't remember which ones exactly, but it seems like dotnet 2.1.2 was spending most of its time in Linux system calls. If I get a chance, I might try profiling again with dotnet 2.1.3 and see if it makes any difference.
richlander commentedon Nov 7, 2018
@dlech - want to test your fuzzy thinking relative to 1.x having better perf?
bradygaster commentedon Nov 7, 2018
@stephentoub just curious what you mean by the fragility? Issue 489 has been linked to this issue, and we'd planned on releasing the RTM of the tool with .NET Core 2.2, but we're going to ship it as a preview given the degraded experience for Ubuntu users and hope to have a fix in place in time for us to RTM (or fully release) the tools in the 3.0 time frame.
I'd like to understand the fragility the fix would cause - we definitely don't want to ask that a "fragile fix" get shipped, but we do want to improve the experience for our Ubuntu users. I'd also like to understand the solution @wtgodbe mentioned above, in which the cursor position protocol might be tweaked. Is there a time frame for this or is it a non-viable solution to this issue?
Thanks all.
stephentoub commentedon Nov 8, 2018
I meant that such an approach would require the System.Console implementation to always have a perfect mirror of exactly where the cursor is. That means it needs to know and be able to hook / react to everything that could possibly move the cursor, including various key strokes, mouse clicks and drags, window resizing, window scrolling, etc., plus such actions hooked by child processes launched by it, etc. I expect it can be done, but the fragility comes from having confidence that we've done it 100% correct. If we miss something, then the System.Console knowledge of where the cursor is could be very out of sync from where it actually is.
I'm not sure what @wtgodbe was referring to. Will?
dlech commentedon Nov 8, 2018
I just ran the example code with 1.1.10 and it seems to be as slow as 2.1.x.
richlander commentedon Nov 8, 2018
That's exactly what I was expecting you'd say @stephentoub.
@bradygaster -- does 'top' do anything similar to what you want?
bradygaster commentedon Nov 8, 2018
@dlech - thanks for verifying the performance is consistent with 1.1.10. that's helpful.
@richlander - this is an interesting consideration.
off the top of my head just imagining visualizing OAI endpoints like this is interesting, but i'm not entirely sure i grok what you're envisioning. mind a sync with @stephentoub and/or @wtgodbe and myself to noodle some ideas friday or next week?
richlander commentedon Nov 8, 2018
@bradygaster I wasn't suggesting emulating the exact top UX. Instead, I was making the point that top writes dynamic data to the console at arbitrary x,y coordinates and has a certain performance profile. Is that super general UX close to what you want?
Look for something else that does what you want and figure out if it has a model we can emulate in some way. The challenge might be that top can do what it does because it is a constrained app with constrained user input. @stephentoub is likely making the point that we don't have the luxury of a constrained environment. That said, if your app is more like top, then maybe you can rely on your own console implementation that doesn't have to make the same generic reliability guarantees as System.Console.
bradygaster commentedon Nov 8, 2018
Got it @richlander. Appreciate the clarification. I'm going to tinker around with
topmore, and also aggressively experiment with thehttpreplto see what I'd want as a user from the experience. I've synced up with @mlorbetske on this briefly, too, to get his ideas on the thread, specifically on this:wtgodbe commentedon Nov 8, 2018
The change that we were considering is essentially what @stephentoub described - that is, maintaining our own understanding of where the cursor is at all times. As he said, though, that can be very tricky to get correct (and difficult to know that we've gotten it correct). @bradygaster if you'd like to chat with Stephen & I next week I'd be happy to do so
KathleenDollard commentedon Nov 14, 2018
Just in case it is relevant...
Ubuntu 18.0.4(*) broke global tools because the
CurrentCulturechanged to en-US-POSIX. Thus code like the following doesn't do what is expected - this code returns false:I could imagine complicating scenarios where something similar raised exceptions, causing exceptions to slow things down and cause general chaos.
This wound up in (the beautifully binary issue number) CLI Issue 10101. It was an easy fix for us, because we should have been using InvariantCulture anyway (oops) - so we just removed all use of CurrentCulture in global tools.
(*) We did not confirm that this is restricted to 18.0.4, it is just where we had it reported and it feels plausible that this is a change in or near 18.0.4
stephentoub commentedon Nov 14, 2018
I don't believe it is, but thanks :)
Just to be clear, CurrentCulture ends up respecting whatever environment is set via environment variables like
LANG, and apparently Ubuntu (or the images of it we're using?) is now defaulting to something far from ideal.cc: @tarekgh
Solve the issue of console flicker (#286)