<span style="color:rgb(49,49,49);word-spacing:1px">Hi,</span><br style="color:rgb(49,49,49);word-spacing:1px"><br style="color:rgb(49,49,49);word-spacing:1px"><span style="color:rgb(49,49,49);word-spacing:1px">I've noticed that `expr` causes LLDB to spend a substantial amount of time on SymbolFileDWARF::</span><wbr style="color:rgb(49,49,49);word-spacing:1px"><span style="color:rgb(49,49,49);word-spacing:1px">ParseDeclsForContext as more types get realized. So I put together a tiny project to try to better understand that behavior, and I was wondering if you guys could help me.</span><br style="color:rgb(49,49,49);word-spacing:1px"><br style="color:rgb(49,49,49);word-spacing:1px"><span style="color:rgb(49,49,49);word-spacing:1px">The project (test.zip) consists of a main function that calls three functions (f1, f2, f3) in an infinite loop. Each function is implemented in its own file and the function itself simply declares a local variable of a type declared inside the function file in an anonymous namespace.</span><br style="color:rgb(49,49,49);word-spacing:1px"><br style="color:rgb(49,49,49);word-spacing:1px"><span style="color:rgb(49,49,49);word-spacing:1px">I added a breakpoint to the loop in main (`cd test && g++ -g -x c++ *.cpp && lldb a.out -o 'b main.cpp:7' -o 'r'`), and tried to evaluate an undefined symbol (`expr undefinedVariable`) inside the loop, then inside each of the functions, and inside of the loop again (`s` and `expr undefinedVariable` four times). To my surprise, the symbols hidden inside the anonymous namespace of the function files would be carried around, regardless of the current scope (custom log trying to describe the calls to ClangASTContext::</span><wbr style="color:rgb(49,49,49);word-spacing:1px"><span style="color:rgb(49,49,49);word-spacing:1px">DeclContextFindDeclByName and SymbolFileDWARF::</span><wbr style="color:rgb(49,49,49);word-spacing:1px"><span style="color:rgb(49,49,49);word-spacing:1px">ParseDeclsForContext - </span><a href="https://pastebin.com/wVhvsFXe" target="_blank" style="font-size:1rem;word-spacing:1px">https://pastebin.com/wVhvsFXe</a><span style="color:rgb(49,49,49);word-spacing:1px">)</span><wbr style="color:rgb(49,49,49);word-spacing:1px"><span style="color:rgb(49,49,49);word-spacing:1px">. So, I have a few questions about that.</span><br style="color:rgb(49,49,49);word-spacing:1px"><br style="color:rgb(49,49,49);word-spacing:1px"><span style="color:rgb(49,49,49);word-spacing:1px">1) Why do we need to keep track of names out of scope?</span><br style="color:rgb(49,49,49);word-spacing:1px"><span style="color:rgb(49,49,49);word-spacing:1px">2) Despite the reason behind 1), aren't we missing an opportunity of caching those compiler declaration contexts somehow so as to avoid iterating over the whole DIE vector inside ParseDeclsForContext every time? If I understood the code correctly, when you run multiple expression evaluations, the vast majority of the `ast_parser-></span><wbr style="color:rgb(49,49,49);word-spacing:1px"><span style="color:rgb(49,49,49);word-spacing:1px">GetDeclForUIDFromDWARF(decl)` calls (</span><a href="https://github.com/llvm/llvm-project/blob/23f70e83594f650830764cca446fdfcba7368460/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp#L1195" target="_blank" style="font-size:1rem;word-spacing:1px">https://github.com/llvm/llvm-<wbr>project/blob/<wbr>23f70e83594f650830764cca446fdf<wbr>cba7368460/lldb/source/<wbr>Plugins/SymbolFile/DWARF/<wbr>SymbolFileDWARF.cpp#L1195</a><span style="color:rgb(49,49,49);word-spacing:1px">) will end up having no side effect as those DIEs will already be in the DWARFASTParserClang::m_die_to_</span><wbr style="color:rgb(49,49,49);word-spacing:1px"><span style="color:rgb(49,49,49);word-spacing:1px">decl map (</span><a href="https://github.com/llvm/llvm-project/blob/af44f18ad66b4f7bbe6a8f6ffa29637a4a5aeea1/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp#L3315" target="_blank" style="font-size:1rem;word-spacing:1px">https://github.com/llvm/llvm-<wbr>project/blob/<wbr>af44f18ad66b4f7bbe6a8f6ffa2963<wbr>7a4a5aeea1/lldb/source/<wbr>Plugins/SymbolFile/DWARF/<wbr>DWARFASTParserClang.cpp#L3315</a><span style="color:rgb(49,49,49);word-spacing:1px">)</span><wbr style="color:rgb(49,49,49);word-spacing:1px"><span style="color:rgb(49,49,49);word-spacing:1px">.</span><br style="color:rgb(49,49,49);word-spacing:1px"><br style="color:rgb(49,49,49);word-spacing:1px"><span style="color:rgb(49,49,49);word-spacing:1px">I'm sorry for the lengthy email.</span><br style="color:rgb(49,49,49);word-spacing:1px"><br style="color:rgb(49,49,49);word-spacing:1px"><span style="color:rgb(49,49,49);word-spacing:1px">Many thanks!</span><div dir="auto"><font color="#313131"><span style="word-spacing:1px">Guilherme<br></span></font><div dir="auto"><span style="color:rgb(49,49,49);word-spacing:1px"><br></span></div></div>