Loading large single-line text is very slow.

SyntaxEditor for WPF Forum

Posted 4 years ago by Sunshine - Appeon
Version: 21.1.2
Avatar

For example, a 600K Css production-level file would have 600,000 characters on a single line.Such files often appear in the project directory after the front-end project is compiled.

Although it is almost unreadable, it takes a long time when the user clicks to open it.

There are two main problems I have encountered so far:

(1)For a large 600K single-line file, Document.Loadfile() method takes about 2 seconds to load. Is there any way to optimize this?

(2)After Document.LoadFile() I want to use the properties on the Document to determine whether the file is a single-line large file to decide whether to register the syntax service.But I don't know when this judgment should be made. When Document.LoadFile() is finished, SyntaxEditor.Document doesn't have any content.

Comments (3)

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

1) We know that it takes a while for WPF's text formatter to run on extremely long lines of text since it has to determine the total width of all the characters on that line for scrollbar max purposes, character bounds for hit-testing, word wrap if that is enabled, and so on.  The only way to really optimize it at this time is to break up extremely long view lines into shorter lines.

2) I tested Document.LoadFile() here and it seemed to work ok.  Please let us know how to reproduce what you are seeing where it's not loading text.

I think the main performance bottleneck with long lines is when formatting view lines.  If you load the document standalone (without a SyntaxEditor attached), you can probably load a document with long lines very quickly, and then adjust it as needed prior to assigning it to the SyntaxEditor.Document property.


Actipro Software Support

The latest build of this product (v25.1.1) was released 2 months ago, which was before the next post in this thread.
Posted 2 days ago by Jiang - Appeon
Avatar

Hi,

I’ve been reviewing the thread Loading large single-line text is very slow and the official reply about how the WPF text formatter struggles when dealing with extremely long lines. The recommendation there was essentially to break up very long view lines.

I’d like to ask a couple of follow-up questions based on the current state of the editor:

  1. I’m currently using SyntaxEditor v24.1.1.
    Has there been any improvement in formatting/layout performance for very long single-line text in recent versions? For example,

    • Have there been optimizations in how scroll range, hit-testing, or wrap calculations are performed?

    • Is there any new feature, flag, or “long line optimization mode” available that can mitigate the performance impact?

  2. In my use case, I must display extremely long single-line content (such as minified JSON) inside SyntaxEditor, while still keeping syntax highlighting (tokenization/classification) enabled.

    • Aside from pre-processing the file to insert line breaks, are there any new recommended approaches for handling this scenario?

    • Are there display-layer optimizations (e.g. deferred formatting, limiting wrap, disabling certain margins) that can help maintain responsiveness with long lines?

    • Any official samples, configuration options, or guidance would be very helpful.

Thanks in advance to the Actipro team and community. Any updates on this topic would be greatly appreciated!

Posted 1 days ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Correct, the main issue is that sending text run to the WPF text formatter is about the most expensive part of SyntaxEditor performance-wise.  When you pair that with an extremely long line, it can really affect performance.  Yet text formatting is required to know how the various glyphs are displayed (syntax highlighting, font size, etc.) and arranged (hit testing, word wrapping, etc.). There is nothing new in the current version compared to v24.1.1 related to that. 

We are currently working on SyntaxEditor updates, and revisiting this issue is one item on the list.  We have seen some editors that have settings to work around similar issues, such as having a maximum number of characters where syntax highlighting can run on, or a maximum number of characters that can be tokenized on a line.  We haven't dug into these ideas yet.

In the current version, reducing the number of characters "formatted" on a line is the key to preventing any performance issues for extremely long lines.  One way to do this is by using collapsed regions.  For instance if you have a 100,000 character line, you could display the first 1,000 and put a collapsed region over the next 8,900 and then just the first 1,000 and last 100 would show and be text formatted.

Another way is by as you said, pre-processing and injecting line breaks.

If you have other suggestions or seen options in other IDE applications that look like they help deal with this issue, it would be helpful to list them here as well for future evaluation.  We are currently in some other areas of SyntaxEditor, but plan on looking into all of this in the coming months.


Actipro Software Support

Add Comment

Please log in to a validated account to post comments.