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

Combine ReadConsoleOutputW calls to potentially reduce scraping CPU usage #44

Closed
rprichard opened this issue Oct 15, 2015 · 0 comments
Closed

Comments

@rprichard
Copy link
Owner

Currently, when scraping the console in scrolling mode, winpty-agent.exe reads each line of the console using a separate ReadConsoleOutputW call. I think each call requires a context switch to conhost.exe / csrss.exe, so consolidating some of the calls might reduce CPU usage.

The OS version matters a lot here. While Windows 8 and up allow arbitrarily large reads, earlier versions of Windows do not. (In fact, with Windows 7, issuing a read of precisely the wrong size can apparently crash conhost.exe. See here for details.)

With Windows 7 and earlier, it is still possible to combine calls, but AFAIK, the console I/O is implemented using a 64KiB heap, and presumably the heap could become fragmented. Because Windows 7 can crash, I'm a little worried about reducing winpty's reliability. That said, winpty already uses a 3000-character read to find the sync marker, so perhaps reads up to that size are OK.

Doing feature detection for this issue seems hard, so maybe winpty will use GetVersionEx. MSDN lists that function as deprecated, because it's been replaced by "version helpers", but I don't think MinGW has the new APIs (even mingw-w64). I think GetVersionEx works up to Windows 8.1, though, so maybe it'll work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant