[cfe-dev] Avoiding unnecessary calls to Decl::getASTContext

David Blaikie via cfe-dev cfe-dev at lists.llvm.org
Sat Dec 15 08:38:29 PST 2018


Seems reasonable and some profile data would help motivate/support/justify
which bits are worth changing and which aren't

On Sat, Dec 15, 2018, 8:27 AM Bruno Ricci via cfe-dev <
cfe-dev at lists.llvm.org wrote:

> Hi all,
>
> I have been looking at Decl::getASTContext and
> DeclContext::getParentASTContext,
> and it turns out that they are not that cheap.
>
> The reason for this is that they must walk back to the translation unit
> declaration
> along what is essentially a linked list. This is amplified by the fact
> that it does
> look like a simple getter and therefore is called extremely often (the
> most egregious
> case by far being DeclContext::lookup), even when most of the times the
> context is
> already easily available.
>
> To put some numbers on this I experimented with removing about half of the
> iterations
> in Decl::getTranslationUnitDecl. This gives a speed up of about 1% when
> parsing all
> of Boost. Extrapolating from this I get that about 1.5%-2% of the time
> spent
> parsing Boost is spent getting the ASTContext, which seems a bit
> unfortunate.
>
> Now to be clear 1.5%-2% is not that much, but the fix is simply to pass a
> ref to
> the ASTContext more often as a function parameter. The downside is that
> this would
> cause a some amount of churn in the C++ api. To be clear I am *not*
> suggesting
> removing all of the calls to Decl::getASTContext, but only removing the
> ones causing
> the most iterations in Decl::getTranslationUnitDecl (say the top 10 or 20).
>
> What do you think ?
>
> Bruno
> _______________________________________________
> 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/20181215/db20d6ba/attachment.html>


More information about the cfe-dev mailing list