Bug 243740 - syntax highlighting slow for long documents
Summary: syntax highlighting slow for long documents
Status: RESOLVED FIXED
Alias: None
Product: frameworks-ktexteditor
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: Ubuntu Linux
: NOR wishlist
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-06 10:45 UTC by Federico Poloni
Modified: 2016-01-31 15:52 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
long LaTeX file (813.73 KB, text/x-tex)
2010-09-03 22:52 UTC, Sergei Ivanov
Details
Add empty lines attribute to MathModeCommon (1.78 KB, patch)
2012-12-20 20:03 UTC, Thomas Braun
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Federico Poloni 2010-07-06 10:45:12 UTC
Version:           2.0.85 (using KDE 4.4.2) 
OS:                Linux

Syntax highlighting when editing a long (~5000 lines) document is slow. Whenever I input a dollar sign, or a "\section{", or anything requiring a re-parsing, in the first part of the document, then the editor hangs for a noticeable time. I suspect this is due to a full re-parsing of the document each time. It would make the interface snappier to perform one only after n seconds, or to parse only the visible part of the screen.

Reproducible: Always

Steps to Reproduce:
1) open a long (~5000 lines) latex document - I can send you the draft of my thesis if you need :)
2) input three or four dollar signs just after the \begin{document}

Actual Results:  
The editor stops responding to user input for a couple of seconds, even on a "modern" computer

Expected Results:  
Syntax highlighting changes almost immediately

OS: Linux (i686) release 2.6.32-23-generic
Compiler: cc
Comment 1 Michel Ludwig 2010-07-07 11:44:35 UTC
Forwarding to KatePart.

I think a general overhaul of the LaTeX syntax file is also due. If I can find some time in the near future, I will have a look at it.
Comment 2 Milian Wolff 2010-07-07 11:50:07 UTC
please provide me with such a long file so I can profile it.
Comment 3 Sergei Ivanov 2010-09-03 22:52:28 UTC
Created attachment 51289 [details]
long LaTeX file
Comment 4 Sergei Ivanov 2010-09-03 22:53:56 UTC
I suffer from this problem too. As you requested, I am attaching a long LaTeX file for testing. It is 200 pages UTF-8 encoded math text in Russian (if you are curios, it is my habilitation thesis). When I type several (20-30) dollar signs at the beginning of this file, kate (or kile or kwrite) stalls and my CPU fan goes crazy. Deleting these dollar signs using backspace has the same effect.

This is with KDE 4.5.1 from Kubuntu PPA packages.

I see three issues to fix here.

(1) katepart should not reparse the entire file after a keypress. At least not when the screen is not updated yet or there are keypresses pending. 

(2) There should be an option to turn the syntax highlighting off. Or, if it is there, a mere mortal should be able to find it.

(3) The LaTeX highlighting rules should be improved. What is wrong now is that an unmatched dollar sign (that is, when a user started a formula but have not yet finished it) makes the whole rest of the file highlighted as math. A natural way to fix this is to let an empty line stop the math mode. After all, this is exactly what LaTeX does. If such a rule is implemented, only the current paragraph would be reparsed while a formula is typed in.

In KDE3 days I had a private patch doing just this, and it made all these speed problems go away. Now I tried to add a line

 <RegExpr String="^\s*$" attribute="Error" context="#pop"/>

within "MathModeCommon" context in latex.xml, hoping that this would do the trick. Unfortunately it did not work (unless empty lines contain some actual space characters) as katepart does not seem to be able to match an empty string.
Comment 5 Dominik Haumann 2010-09-22 22:39:06 UTC
Partly fixed in r1176817. If you type and the context remains the same, no reparsing is done. There is no delayed parsing though, and I'm not sure whether it's feasible to implement.
Comment 6 Christoph Cullmann 2012-11-07 23:15:05 UTC
I have fixed the empty line detection in bug 274289, could somebody enhance the latex xml spec?
Comment 7 Thomas Braun 2012-12-20 20:03:30 UTC
Created attachment 75944 [details]
Add empty lines attribute to MathModeCommon
Comment 8 Thomas Braun 2012-12-20 20:28:01 UTC
The patch should implement the empty line recognition. As I don't have a recent KDE it is untested.

@Sergei Ivanov:
You can turn syntax highlightning off only in the settings menu deep inside kile.
I tried a bit and looked for a workaround, but it just seems that math mode detection is too slow. And making it faster is not that straightforward.
What you can try is to split the document into multiple files and use \input. Oh and inserting "$ $" instead of "$$" is also much faster.
Comment 9 Dominik Haumann 2013-09-10 23:34:48 UTC
Thomas, can you test again with a recent KDE version?
Comment 10 Christoph Cullmann 2016-01-31 15:52:32 UTC
For me that works well and fast with KWrite in the Frameworks 5 version.