You are not logged in.

#1 2018-01-15 14:45:25

bgavran
Member
Registered: 2018-01-07
Posts: 3

High CPU usage when pressing down any key

Hi all!

I've been using Arch for quite some time already but recently I've started having the strangest problem that I've been unable to solve.

I've noticed my entire system has become a tad slow and I went on exploring why. Turns out, I've found a big clue:
If I open htop in one terminal window and just terminal in another one and if I press any key (literally, if I press the key "t" and let the terminal just print "ttttttt"), htop CPU usage of process "zsh" (I'm using zsh) starts going up.
If I hold the key for a longer period, it gets up to 100%.

The problem? It's not happening with just terminal and not just with just zsh. If I do the same with Chrome window and start typing "ggggggg" in the address bar, the cpu usage goes up as well. Same thing happens with Firefox and same thing happens with pretty much any application I tried.
The only scenario is when it doesn't happen is if I open up bash and start typing. In that case, nothing unusual happens and system acts as expected.
One other place where it doesn't happen is the tty: by pressing down a key there it doesn't increase the cpu and it actually seems like the repeat rate of the letter is higher; it seems like the system is generally faster.

I'm not sure where to even look for the solution to this problem. My conclusions is that it's not a hardware problem because there are scenarios where it doesn't appear. Also, if I'm pressing down a key in an app, but the letters aren't getting displayed (end of the line or there's nowhere to type), the CPU usage doesn't go up. So it means it has to do something with actually displaying the letter on the screen?

I'm using the up-to-date version of Arch with i3 window manager and polybar. htop doesn't show any unusual processes and neither does iotop. This is the output of my screenfetch:

 bgavran3@bgavran3-pc
 OS: Arch Linux
 Kernel: x86_64 Linux 4.14.13-1-ARCH
 Uptime: 1h 0m
 Packages: 1611
 Shell: zsh 5.4.2
 Resolution: 1366x768
 WM: i3
 GTK Theme: Arc-Darker [GTK2/3]
 Icon Theme: Moka
 Font: Sans 10
 CPU: Intel Core i5-4200U @ 4x 2.6GHz [71.0°C]
 GPU: intel
 RAM: 4183MiB / 11932MiB

Let me know if you need me to provide any other information about the system!

Offline

#2 2018-01-17 16:37:52

mkkot
Member
From: Poland
Registered: 2009-12-20
Posts: 287

Re: High CPU usage when pressing down any key

I have same, when I hold key in firefox, it goes to 110% of cpu. But this doesn't make my system slow. Probably you are chasing ghosts in wrong place.

Offline

#3 2018-01-17 19:29:01

bgavran
Member
Registered: 2018-01-07
Posts: 3

Re: High CPU usage when pressing down any key

You are saying that CPU going to >100% when pressing down key is a feature, rather than a bug?
Is there a resource where I can read more about what is actually happening? Googling various combinations of phrases related to the problem doesn't seem to yield anything useful.

Offline

#4 2018-01-17 20:15:28

mkkot
Member
From: Poland
Registered: 2009-12-20
Posts: 287

Re: High CPU usage when pressing down any key

Maybe lets call it design fault. What happens if you try to lower your keyboard key repetition speed in DE's settings?

Offline

#5 2018-01-17 20:49:25

null
Member
Registered: 2009-05-06
Posts: 398

Re: High CPU usage when pressing down any key

I also get 100% in zsh and firefox but not in bash or sh. If I had to guess I'd say that this is expected behaviour on text fields that are doing stuff with the input while we type. In my setup zsh checks all the inputs and colorizes it while I'm typing. If I hold down a key the input is very fast so zsh probably is checking the hell out of your input. Firefox probably does similar things to give you links from your history or your bookmarks while you're typing.

I wouldn't go as far as calling it a feature but definitly not a bug. It's just more input than those programs can handle, but there is no need to fix that, because the only way we can type that fast is if we type nonsense..

But to come back to your actual problem: what exactly do you mean by

I've noticed my entire system has become a tad slow

? And do you have a composite manager running? If not, have you tried xcompmgr or similar? I had a very slow desktop once with dwm (everything was tearing and when I moved a window very fast I had to wait up to a few seconds to have it at it's destination). The CPU just couldn't draw those windows properly onto the 1920x1080 screen. Since I've got xcompmgr running the GPU does it and everything is smooth..

Offline

#6 2018-01-17 21:47:19

seth
Member
Registered: 2012-09-03
Posts: 51,039

Re: High CPU usage when pressing down any key

Siding with mkkot & null here.

As for zsh: any chance you're using OMZ or powerline?
The browsers will likely search your history, maybe even online suggestions.

null wrote:

Since I've got xcompmgr running the GPU does it and everything is smooth..

Actually it's more likely because the compositor serves as a backbuffer. W/o, every pixel you move an (opaque) window causes an exposure event and requires alls sublying windows to re-render (the exposed area)
Depending on what the windows render (and whether they have internal caches) this can be very slow. The compositor just blits the pixmap (or texture) of the window what costs nothing - GPU or not.

Offline

#7 2018-01-19 13:13:53

bgavran
Member
Registered: 2018-01-07
Posts: 3

Re: High CPU usage when pressing down any key

null wrote:

I also get 100% in zsh and firefox but not in bash or sh. If I had to guess I'd say that this is expected behaviour on text fields that are doing stuff with the input while we type. In my setup zsh checks all the inputs and colorizes it while I'm typing. If I hold down a key the input is very fast so zsh probably is checking the hell out of your input. Firefox probably does similar things to give you links from your history or your bookmarks while you're typing.

Nobody I know has this sort of an issue and I still find it very strange! Although, what you're saying kind of makes sense.

null wrote:

But to come back to your actual problem: what exactly do you mean by

I've noticed my entire system has become a tad slow

? And do you have a composite manager running? If not, have you tried xcompmgr or similar? I had a very slow desktop once with dwm (everything was tearing and when I moved a window very fast I had to wait up to a few seconds to have it at it's destination). The CPU just couldn't draw those windows properly onto the 1920x1080 screen. Since I've got xcompmgr running the GPU does it and everything is smooth..

Right, I think you're spot on!
I do have a composite manager running, compton. After googling a bit, I've found these issues:
https://github.com/chjj/compton/issues/152
Turns out, adding the --xrender-sync fixes the problem of the system being laggy. Pressing the key still makes CPU go up to 100%, but there is no noticeable lag.

Offline

Board footer

Powered by FluxBB