[Interest] Can a view somehow notify a model of which rows it is going to show on screen?

Jan Kundrát jkt at flaska.net
Fri Apr 25 14:35:30 CEST 2014


On Tuesday, 22 April 2014 23:51:07 CEST, Mark Gaiser wrote:
> There we have it. All visible item indexes accurately known. :)

The model does not know if there's any view attached to it, though.

> Usecase:
> If you only look at small folders then this definitely is premature
> optimizations since the "regular sorting" will do just fine there.
> Bit if you look at insanely massive folders with 500.000 items. All
> stuffed in one ListView (where you only see ~50 or so). Sorting that
> by string in a natural way (using QCollator) is very slow. In my case
> ~6 seconds.

Six seconds to sort 500k items doing a locale-aware string comparison 
sounds like a bug. Check this:

svist ~ # locale | grep CTYPE
LC_CTYPE=cs_CZ.utf8
svist ~ # wc -l /var/log/messages 
763524 /var/log/messages
svist ~ # time sort /var/log/messages > /dev/null

real    0m0.244s
user    0m0.555s
sys     0m0.055s

763k items just got sorted in a fraction of a second, including (cached) IO 
and printing to stdout. Sure, these items were actually presorted (my log 
was the easiest think to work on, and it's ordered already), but if you 
need six seconds for something so trivial, your program has a bug.

Use a profiler. Take a look at where the time is spent. You mentioned "a 
folder" -- are you doing stuff like directory IO in there, and including 
that in your measurements? Again, profile, measure, do not guess. And do 
not try to fight file IO by doing partial sorts.

> I know that giving a ListView a task with that many items
> is insane and in most cases you're probably better of splitting the
> data in chunks. 

That said, introducing deliberate chunking is also ugly from the user's 
POV.

Cheers,
Jan

-- 
Trojitá, a fast Qt IMAP e-mail client -- http://trojita.flaska.net/



More information about the Interest mailing list