edbee / edbee-lib

QWidget based Text Editor Component for Qt. Multi-caret, Textmate grammar and highlighting support.
Other
75 stars 26 forks source link

markAll() - slow for many matches #99

Closed vadi2 closed 3 years ago

vadi2 commented 4 years ago

We've got this bit of code that we're using to highlight search matches:

    auto controller = mpSourceEditorEdbee->controller();
    auto searcher = controller->textSearcher();
    controller->borderedTextRanges()->clear();
    controller->textSelection()->range(0).clearSelection();
    searcher->setSearchTerm(text);
    searcher->markAll(controller->borderedTextRanges());
    controller->update();

And when we use it on say a 1,000 line document like this, highlighting a single character like c takes a really long while:

Selection_142

Are we using the API right or is there something that can be done?

We've already disabled highlighting for one or two character searches, but that's more of a workaround than a solution, since VS Code on the same machine handles it okay.

gamecreature commented 4 years ago

That does't sound very good. I have to look into this. ( Unfortunately I don't have much time these days for Edbee).

My first impression is that the markAll and searchAll functions are very inefficient, because it uses a 'findNextRange' call for every item searched.

FindNextRange is a method that can called separately. A much better approach would be to use 1 call that uses the regexp just once in a loop. So an optimised rewrite of markAll without calling findNextRange would be a solution

Btw. VSCode probably uses threading for searching in the background.

gamecreature commented 4 years ago

@vadi2 Could you check if this improves the situation?

vadi2 commented 3 years ago

We are good on this now, thank you :+1: