Bug 439614 - Running commands in Konsole becomes slow / laggy when it has been open a long time
Summary: Running commands in Konsole becomes slow / laggy when it has been open a long...
Status: RESOLVED NOT A BUG
Alias: None
Product: konsole
Classification: Applications
Component: general (show other bugs)
Version: 21.04.2
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: Konsole Developer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-07-07 20:19 UTC by Adam Fontenot
Modified: 2022-04-13 03:35 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
desktop recording of konsole slowdown problem (291.93 KB, video/x-matroska)
2021-07-07 20:19 UTC, Adam Fontenot
Details
perf profile for konsole (1.09 MB, application/octet-stream)
2021-07-08 00:50 UTC, Adam Fontenot
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Fontenot 2021-07-07 20:19:00 UTC
Created attachment 139927 [details]
desktop recording of konsole slowdown problem

SUMMARY

I have a Konsole instance that has been running for about a week. I've been using it every day for various tasks (system updates, utilities that print things, and so on). Now, new commands take far too long to execute. (The processes themselves still run just as quickly, but Konsole is slow to print the output.)

I've included a video of this happening. In the foreground you can see an XTerm instance which shows the exact frame I press the enter key on. If you count the frames from the instant the <enter> key is shown, Konsole consistently takes around 37 frames to show the result. As this video was recorded at ~60 fps, that's over 0.6 seconds and is easily noticeable to the user.

As you can see in the video, I run the command using `time`, and the program runs in about ~0.05 seconds. In other words, over half a second of the time to return to the shell prompt is due to Konsole's output lagging.

Typing in the terminal is *not* noticeably slow.

Ctrl-shift-n to open a new window *does not* solve this problem. The resulting window is running under the same Konsole pid as the existing window, and is just as slow. If I start a new Konsole instance (e.g. by entering `konsole` at the prompt in Konsole), it is not slow. 

The reason I didn't show `echo test` in the video is that this command (which uses the zsh echo built-in) is almost always very fast. Once out of every 10 or 20 times I enter it it'll lag slightly. I'm not sure why this behaves differently than the command I show in the video.

STEPS TO REPRODUCE
1. Leave Konsole running for a long time and do normal tasks in it from time to time
2. Try to run a simple command that should return ~instantly

OBSERVED RESULT

Konsole takes a lot of time to print the output from commands and return to the shell prompt.

EXPECTED RESULT

Konsole should take the normal amount of time to do the above.

SOFTWARE/OS VERSIONS
Linux: Arch Linux x86_64 kernel version 5.12.13
KDE Plasma: 5.22.2
KDE Plasma Version: 5.22.2
KDE Frameworks Version: 5.83.0
Qt Version: 5.15.2

ADDITIONAL INFORMATION

I have a fairly large scrollback of 100k lines, but my system is not even close to being out of memory. I have a pretty decent number of terminals open under this PID right now.

I have "reflow lines" enabled (I think it's a default). It's the only other thing I've ever seen slow down Konsole - if I accidentally print an extremely long line (millions of characters), Konsole can slow to a crawl. I don't have a good reason for thinking it's related.

I will try to leave this Konsole instance running for at least another day or two, in case anyone has debugging steps they would like me to try.
Comment 1 ninjalj 2021-07-07 21:53:29 UTC
A profile, e.g. using perf, may show something.

To record a profile for konsole:

perf record -g -p <pid of konsole>

A profile of the whole system may be interesting:

perf record -g

The profile can be analyzed with:

perf report
Comment 2 Adam Fontenot 2021-07-08 00:50:13 UTC
Created attachment 139934 [details]
perf profile for konsole

(In reply to ninjalj from comment #1)
> A profile, e.g. using perf, may show something.
> 
> To record a profile for konsole:
> 
> perf record -g -p <pid of konsole>

Attached. Profile contains about 15 seconds of recording during which I ran `python -S -c "print('test')"` 3 times.
Comment 3 Adam Fontenot 2022-04-13 03:35:24 UTC
I believe I managed to track down the cause of this, and I don't think it's a Konsole bug. It's actually because I'm using ZSH as my shell. It has some complicated options that try to interweave the history for all active shells, and it looks like this history isn't getting finalized and flushed to the history file until all active ZSH shells are closed (or possibly until a logout happens?). The result of this is that the in-memory version of the history gets more and more complicated over time, and this results in extreme input lag.

Closing this under the assumption that ZSH is to blame.