<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/96570>96570</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang-doc] Clang-Doc is extremely slow in producing generating LLVM docs
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
PeterChou1
</td>
</tr>
</table>
<pre>
@ilovepi, @petrhosek
Currently clang-doc is extremely slow in producing LLVM docs, it consumes a ton of memory and kills my machine every time I attempt to generate the LLVM docs. This is extremely unusual since doxygen, and other equivalent tools such hdoc to generate documentation is able to produce LLVM docs with significantly less memory and speed. This presents a tremendous challenge if we want clang-doc to eventually replace doxygen generated docs for LLVM.
During my investigation I found that clang-doc has similar performance for small project as equivalent tools. But for large projects the performance deviates drastically.
I was able to use llvm TimeTraceProfiler to set a profile of clang-doc when it was attempting to generate llvm documentation
here's the tracing json file: https://drive.google.com/file/d/1GSO-eRKiSv_g4yxtHTXFuz1yi7SXpeMH/view?usp=sharing
![image](https://github.com/llvm/llvm-project/assets/43522225/999aa65c-10a4-4766-aa91-fe00acc2bd82)
The majority of runtime appears to be dominated by the reduction phase, with Reading the Bitcode dominating alot of the time
I think this problem is due to clang-docs the way clang-doc is architected,
Currently clang-doc uses RecursiveASTVisitor to visit every Namespace/Record/Method/Function/Typedef/TypeAlias Decl in the compilation database. Every time clang-doc visits a Decl it saves Info on the Decl itself and creates an Info about the parent Decl and insert itself into it.
Instead of doing this I think we should just compute all child records, typdef and etc whenever clang-doc during the recursive AST visit to a namespace or record instead of attempting to do a merge after. This is the conventional approach taken by most of the other doc generators using libtooling for documentation.
This approach has the advantage of removing the reduction step, to gather all the info needed for a Decl, which should speedup clang-doc.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVk9zOrkR_TTDpcsUiD82Bw62CVlX9pds2dTW3lKN1DMjWyNN1BL8y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