Nominate our 2022 Qt Champions!

QLineEdit based completer for combo, search on type, awful performance

  • Hello.

    I have a completer based on QLineEdit. It searches for regular expressions and update the dropdown list with the relevant results while you type. The regexps are basically concatenations of substrings, like ".*sp.door." which would match "special door", "another spanish doorway" or the like. Just a couple of silly examples.

    The problem is that setCompleter() is called each time a new character is typed, and, for each iteration, it compares the current regexp against every record in the database, that has a current rowCount() > 60k. To make it worse, it's sqlite. So, Houston, we definitely have a problem.

    I am looking for suggestions in how to make this a bit more efficient. I have been thinking on making some kind of recursive function that would create a new filtered proxy model on each iteration, so that the next one would hopefully be more efficient. However, the first two keypresses would hang the UI for half a minute, I presume... That is, until the search term narrows the list a bit.

    I have also been thinking about implementing some kind of delay so that, if you are gonna type "spec" it doesn't iterate across 60k items four times, but, instead, waits until the "spec" substring has been typed and then fire up the search, after a reasonable delay (3-4 secs or so, I guess).

    I could dump this altogether and implement a search dialog, but I am sure there must be a solution. Most modern applications do implement this kind of in-line search, and also web applications (for example, that silly facebook bar that returns the results almost instantly when searching for users, in a database set that is no doubt much larger than mine).

    So, how do people face this kind of problem nowadays?

    I can show the code if needed. But I am looking more for the general idea than for concrete code.

    Thanks for any tip :)

  • Lifetime Qt Champion


    Not really a tip but you could compare your implementation to the "Custom Completer Example"

    Hope it helps

  • Sorry for taking so long to come back, and thanks for the response.

    [quote author="SGaist" date="1394317184"]Hi,

    Not really a tip but you could compare your implementation to the "Custom Completer Example"

    Hope it helps[/quote]

    I've been postponing this (and continue to do so) because of some other things that needed attention. I certainly looked at the example, and built my own completer using that and a few other things I found around the net.

    However, my understanding of the whole model-view thing one year ago (which is probably when this all started) was far poorer what it's now. So your post was enlightening in a sense... maybe I should re-visit this when I have enough time to do so. Maybe then I will be able to make a more concrete question in any case.

    Again, thank you :)

Log in to reply