Bug 466531

Summary: Kate stops responding after pasting a very long line
Product: [Applications] kate Reporter: Christopher Yeleighton <giecrilj>
Component: foldingAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED WORKSFORME    
Severity: normal CC: waqar.17a
Priority: NOR    
Version First Reported In: 22.12.2   
Target Milestone: ---   
Platform: openSUSE   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Christopher Yeleighton 2023-02-27 15:02:37 UTC
SUMMARY
Kate stops responding after pasting a very long line.


STEPS TO REPRODUCE
1. Paste a very long line without blanks to a new text document.

OBSERVED RESULT
1. Kate does not respond to cursor keys or mouse clicks in the buffer.

EXPECTED RESULT
2. Let Kate refuse to paste a line that is too long for it to handle!

SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: openSUSE Tumbleweed 20230225
(available in About System)
KDE Plasma Version: 5.27.1
KDE Frameworks Version: 5.103.0
Qt Version: 5.15.8

ADDITIONAL INFORMATION
Comment 1 Waqar Ahmed 2023-02-27 15:29:44 UTC
> 2. Let Kate refuse to paste a line that is too long for it to handle!

That's not going to happen simply because can't know what's too long to handle. For me even very long lines work fine, for someone else the same stuff might not as everyone runs different kind of hardware.

That said, maybe we can profile and fix the issue if possible. However, it may not be possible as Kate in general doesn't behave well with very long lines. We have had many reports around this, probably this bug itself is a dupe of some other. Anyways, can you try to attach to Kate from the Hotspot[1] app. Hotspot is available in most distros. 

- Attach to kate from hotspot
- start recording
- Paste long line / make kate slow
- wait 4 or 5 seconds
- stop recording
- share the perf output / screenshots of the flamegraph

[1]: https://github.com/KDAB/hotspot
Comment 2 Waqar Ahmed 2023-03-03 14:20:30 UTC
Can you share the following information?

- What are your indenter settings?
- Have you enabled Indent on Paste?
- What is your "Default Indenter"?
- What was the filetype of document that you pasted the text into?
- Can the line of text which makes kate slow be shared?
Comment 3 Bug Janitor Service 2023-03-03 14:27:19 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/ktexteditor/-/merge_requests/493
Comment 4 Christoph Cullmann 2023-03-03 20:15:20 UTC
Git commit 294543a2977c4181bb0842c2a45f573f8335fd03 by Christoph Cullmann, on behalf of Waqar Ahmed.
Committed on 03/03/2023 at 19:42.
Pushed by cullmann into branch 'master'.

Improve cstyle performance

With this patch I can notice 7x-8x improvement in performance. The main
culprit was `tryMultiLineStringLiteral` which searched the whole document
for a multiline literal beginning. I have now limited it to 25 lines max.

Besides, the multiline string matching is useless for every other language
besides C++ so return early if the mode is no C++
Related: bug 465841

M  +1    -0    autotests/input/indent/cstyle/indentpaste5/expected
M  +1    -0    autotests/input/indent/cstyle/indentpaste5/origin
M  +1    -0    autotests/input/indent/cstyle/string2/expected
M  +1    -0    autotests/input/indent/cstyle/string2/origin
M  +9    -0    src/script/data/indentation/cstyle.js

https://invent.kde.org/frameworks/ktexteditor/commit/294543a2977c4181bb0842c2a45f573f8335fd03
Comment 5 Waqar Ahmed 2023-03-04 08:56:29 UTC
Git commit 67e566875597f0c1b1c0e0fafc482efcf4512b88 by Waqar Ahmed.
Committed on 04/03/2023 at 08:55.
Pushed by waqar into branch 'kf5'.

Improve cstyle performance

With this patch I can notice 7x-8x improvement in performance. The main
culprit was `tryMultiLineStringLiteral` which searched the whole document
for a multiline literal beginning. I have now limited it to 25 lines max.

Besides, the multiline string matching is useless for every other language
besides C++ so return early if the mode is no C++
Related: bug 465841

M  +1    -0    autotests/input/indent/cstyle/indentpaste5/expected
M  +1    -0    autotests/input/indent/cstyle/indentpaste5/origin
M  +1    -0    autotests/input/indent/cstyle/string2/expected
M  +1    -0    autotests/input/indent/cstyle/string2/origin
M  +9    -0    src/script/data/indentation/cstyle.js

https://invent.kde.org/frameworks/ktexteditor/commit/67e566875597f0c1b1c0e0fafc482efcf4512b88
Comment 6 Bug Janitor Service 2023-03-19 03:45:42 UTC
Dear Bug Submitter,

This bug has been in NEEDSINFO status with no change for at least
15 days. Please provide the requested information as soon as
possible and set the bug status as REPORTED. Due to regular bug
tracker maintenance, if the bug is still in NEEDSINFO status with
no change in 30 days the bug will be closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

If you have already provided the requested information, please
mark the bug as REPORTED so that the KDE team knows that the bug is
ready to be confirmed.

Thank you for helping us make KDE software even better for everyone!
Comment 7 Bug Janitor Service 2023-04-03 03:45:22 UTC
This bug has been in NEEDSINFO status with no change for at least
30 days. The bug is now closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

Thank you for helping us make KDE software even better for everyone!