[cfe-dev] Clang-based autocompletion speed

Milian Wolff via cfe-dev cfe-dev at lists.llvm.org
Mon Jan 11 13:41:03 PST 2016


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160111/d113f355/attachment.sig>


More information about the cfe-dev mailing list