[cfe-dev] Clang-based autocompletion speed

Anders Bakken via cfe-dev cfe-dev at lists.llvm.org
Tue Jan 12 22:30:11 PST 2016


What we do in https://github.com/Andersbakken/rtags is to preemptively
generate completion results whenever the cursor is moved (with a short
delay) and then cache them for faster lookup. This seems to help a little
bit at least.

Anders

On Mon, Jan 11, 2016 at 1:41 PM, Milian Wolff via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> On Donnerstag, 7. Januar 2016 21:34:10 CET Maksym Taran via cfe-dev wrote:
> > Hello!
> >
> > I'm looking into improving how an autocomplete system at Google
> > computes semantic
> > autocompletions for a given C++ file + line + column. Currently, it's
> > mostly just calling out to clang_codeCompleteAt
> > <
> https://github.com/llvm-mirror/clang/blob/52ed5ec631b0bbf5c714baa0cd83c33eb
> > fe0c6aa/tools/libclang/CIndexCodeCompletion.cpp#L798>, and that's where
> > we've been seeing high latency.
> >
> > A particular problem we're having is that when we try to autocomplete
> just
> > within some scope (that is, just inside a function body, rather than
> after
> > a . or -> etc), calling that method returns *all* possible autocompletion
> > results, which includes all constants and class names defined in all the
> > transitively included files as far as I can tell. This is technically
> > correct, but in practice takes on the order of seconds to return, which
> is
> > much longer than the desired timeframe for autocompletion results.
>
> How many results do you get after this delay? Using KDevelop to work on
> code,
> I've never seen such long delays just for the code completion stage. What
> takes a long time is the initial parse with clang_parseTranslationUnit2. I
> hope you guys have some sort of daemon which can keep the TU alive? Make
> sure
> you pass CXTranslationUnit_PrecompiledPreamble, but note that the current
> stable releases of clang won't actually save the precompiled preamble to
> disk
> until you call clang_reparseTranslationUnit at least once. It's easy to
> check,
> just look at /tmp and see whether you have preamble-*.pch files in there.
> Once
> you do all of that, you can easily get an order of magnitude increase in
> performance.
>
> > So I'd
> > like to know if there's some way I can get a smaller set of
> autocompletions
> > more quickly, e.g. by asking clang to complete only on method names and
> > locals, or by giving a time limit to get results. I didn't see how I
> might
> > do that in the documentation
> > <
> http://clang.llvm.org/doxygen/group__CINDEX__CODE__COMPLET.html#ga50fedfa85
> > d8d1517363952f2e10aa3bf> so
> > I'm wondering if there are some other APIs I'm not seeing.
>
> I haven't seen such an API either. How do you envision it? Some filter
> callback that one could pass to the clang_codeCompleteAt call?
>
> > I took a look at YouCompleteMe <
> https://github.com/Valloric/YouCompleteMe>
> > and it's using the same API
> > <
> https://github.com/Valloric/ycmd/blob/master/cpp/ycm/ClangCompleter/Transla
> > tionUnit.cpp#L176>, so I suspect it might have the same problem. If
> there's
> > no way to do something like this using the current API methods, I'd be
> > interested to know how possible/difficult would it be to implement
> > additional methods or options?
>
> Adding methods isn't that hard, it just takes time (which I personally lack
> atm to advance my personal WIP patch). Just make sure you build an API
> that is
> future proof and stable, and don't forget your tests.
>
> Cheers
> --
> Milian Wolff
> mail at milianw.de
> http://milianw.de
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160112/1798ba21/attachment.html>


More information about the cfe-dev mailing list