cengels/skywriter

Performance / responsiveness to inputs

cengels opened this issue · 3 comments

This issue is a catch-all issue to diagnose and fix all and any problems related to the performance and/or the general input responsiveness in Skywriter.

The search suffers from massive performance problems. In other applications, even in large files (1 MB+), something as small as 1 character search results return instantly. Conclusion: there must be a better way to implement a search that is considerably more performant.

It must be diagnosed whether the problem is the actual search itself or the visual highlighting of the search results.

The cause of the search performance issues is indeed the QSyntaxHighlighter, or more specifically TextHighlighter::refresh(). Normally the QSyntaxHighlighter automatically calls QSyntaxHighlighter::highlightBlock() whenever a text block changes, but this means that external changes (such as entering a new search term) do not trigger a rehighlight. To remedy this, manually calling rehighlight() (or, in TextHighlighter called refresh()) is necessary.

It doesn't really make sense to me why the rehighlighting takes so long. We're applying quite a lot of formats, yes, but none of the search term highlighting formats modify the text layout in any way. Thus, this should not trigger a relayout, which is the only potential cause I can see for such a performance impact.

An alternative solution might be to move the search term highlighting code to updatePaintNode, but that seems a little hacky and I'd like to avoid that if possible.

Unfortunately, simply making the QSyntaxHighlighter asynchronous is (probably) not an option since it operates directly on the UI thread, where it must stay.

All performance issues related to the search (see above) are now resolved.