let's optimize: Project::itemsForUrl

Andreas Pakulat apaku at gmx.de
Fri Sep 9 19:53:44 UTC 2011


On 09.09.11 18:06:35, Milian Wolff wrote:
> Milian Wolff, 09.09.2011:
> > Hey all,
> > 
> > the function Project::itemsForUrl is *really* slow when we look at the
> > total amount of time spent in there when parsing a biggish project. I just
> > did that (with a simple QTimer and a static elapsed counter) and the last
> > output was:
> > 
> > QList<KDevelop::ProjectBaseItem*>
> > KDevelop::ProjectPrivate::itemsForUrl(const KUrl&) const elapsed time:
> > 56870
> > 
> > Yes, nearly a minute was spent in that function. So I would really like to
> > improve that.
> > 
> > The code/apaku already mentions this:
> > 
> >         // TODO: This is moderately efficient, but could be much faster
> > with a // QHash<QString, ProjectFolderItem> member. Would it be worth it?
> > 
> > I'm pretty sure he meant ProjectBaseItem. The question is, how to keep that
> > in sync. We could put that into the ProjectModel and update it on every
> > call to setUrl (if model()) and in setModel. I'm not so sure on the memory
> > requirements though. We could of course just reuse IndexedString's new
> > indexForString method, so the mem requirement would be (sizeof(uint) +
> > sizeof(ProjectBaseItem*)) * N_items. Which is only a bit more than a
> > megabyte on my machine (64Bit) for 100k items.
> 
> Implemented this one now and it seems to work like a charm. please test and 
> report back :)

Did you also try the prefix-check? I'm wondering wether its efficient
enough to avoid the memory-overhead (since kdevelop already has quite a
bit of that) at all.

Andreas





More information about the KDevelop-devel mailing list