[early patch] Speed up decl chaining

Rafael EspĂ­ndola rafael.espindola at gmail.com
Fri Oct 18 20:35:05 PDT 2013


> Currently decl chaining is O(n). We use a circular singly linked list
> that points to the previous element and has a bool to say if we are
> the first element (and actually point to the last).
>
> Adding a new decl is O(n) because we have to find the first element by
> walking the prev links. One way to make this O(1) that is sure to work
> is a doubly linked list, but that would be very wasteful in memory.
>
> What this patch does is reverse the list so that a decl points to the
> next decl (or to the first if it is the last). With this chaining
> becomes O(1). The flip side is that getPreviousDecl is now O(n).

The patch still needs work, but I managed to convert all calls to
getPreviousDecl in the above testcase. In my machine the clang -cc1
time on it goes from  4.819s to 0.865s now (5.57x faster).


Cheers,
Rafael
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t.patch
Type: application/octet-stream
Size: 46303 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131018/ba8c3d1f/attachment.obj>


More information about the cfe-commits mailing list