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

Optimize CPU when Window is Hidden or Minimized #875

Closed
numeralnathan opened this issue May 16, 2019 · 8 comments
Closed

Optimize CPU when Window is Hidden or Minimized #875

numeralnathan opened this issue May 16, 2019 · 8 comments

Comments

@numeralnathan
Copy link

I am doing a long operation with tee to see the progress. So far 60 GB of text was written to the console. I noticed that mintty.exe consumes 20% CPU on a 4 logical core machine. If I minimize the mintty window or put another window in front of mintty, mintty still consumes 20% CPU.

Please optimize mintty to not use as much CPU when the window is hidden. Ideally, mintty would simply copy stdout from tee to an in-memory buffer and do nothing more. Then when the mintty window is displayed, mintty will consume CPU time to render the screen.

This is a trick that Windows Command Prompt does. It significantly speeds up long operations.

@BrianInglis
Copy link

I've never caught mintty using any significant CPU: only a few % doing cat /var/log/*, and it drops when the window is obscured. What type of content are you displaying, what CPU are you running on, and how are you measuring this? If you are displaying a lot of exotic Unicode scripts, unassigned glyphs looking up fallbacks, escape sequences, or the like, rendering could be slower. Some tools can report CPU used by child processes and threads consolidated up to the parent: this may be what you're seeing. Use a tool or option that breaks down the CPU displayed by that consumed by each process or thread. You could run the process to write the log in the background, and use xtail to track log progess in the foreground.

@mintty
Copy link
Owner

mintty commented May 16, 2019

It might be possible to suspend the timer-driven window display updating while the window is hidden but mintty would still need to process the actual terminal output. But as Brian says, both is unlikely to be the culprit and it would be needed to demonstrate a case of mintty actually consuming much CPU time to establish whether it's worth the effort.

@numeralnathan
Copy link
Author

I am display plain ASCII text. I am running on an Intel Core i5-7300U. I am measuring this by looking at Process Explorer. It shows the CPU usage of each process running on the system. It only reports the CPU usage of the process and does not add in the CPU usage of the child processes.

That is a good idea to write the log in the background and tail in the foreground.

I generated a random file with base64 /dev/urandom | head -c 10000000000 > random.txt. I then executed cat random.txt and see mintty.exe almost maxing out 1 core.

Here is the output from Process Explorer with the mintty window showing while executing cat random.txt.

image

Here is the output from Process Explorer with the mintty window minimized while executing cat random.txt.

image

The above emulates what I was seeing while executing grep.

@mintty
Copy link
Owner

mintty commented May 17, 2019

If you feed unlimited input at maximum speed into the terminal, it's not surprising that it uses a maximum of CPU load to swallow it. Same with xterm.

@Biswa96
Copy link
Contributor

Biswa96 commented May 18, 2019

In the screenshot, the processes icons looks like compressed (small blue arrows). Are you running those from a compressed drive?

@mintty
Copy link
Owner

mintty commented May 18, 2019

Running minimized during output saves ~10% elapsed time already.
If I tentatively suppress screen rendering while minimized, it does indeed save ~30% elapsed time.
Note, however, that in both cases, the CPU load is not reduced because your scenario is effectively a load test which will by its nature always drive the load to a maximum.

@mintty
Copy link
Owner

mintty commented May 18, 2019

With option DisplaySpeedup=0 (default before 2.9.6) the relative speedup would be much higher.
Whatever, it's easy to apply the iconic speedup optimization.

@mintty
Copy link
Owner

mintty commented May 28, 2019

Released 3.0.1.

@mintty mintty closed this as completed May 28, 2019
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

No branches or pull requests

4 participants