[Lldb-commits] [lldb] [lldb] Fix ForwardListFrontEnd::CalculateNumChildren (PR #139805)

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Wed May 14 01:48:05 PDT 2025


labath wrote:

I'm very much in favor of removing this dependence on the setting value, as I think it should be handled at a higher level. *However*, I fear this is going to make printing large std::forward_list very slow. Since computing the size of the list requires iterating through all the elements, which is a lot of pointer chasing, printing of large lists (like, 10k elements or more) could take a very long time (and I think that's the reason this limit was originally introduced).

Fortunately, we already have a mechanism to prevent this -- we mave `GetNumChildren` overload with the `max` argument which basically says "if the number of children is larger than this, don't bother giving me the exact value". The general printing logic (in frame var and lldb-dap) should already know how to make use of this (I've made sure of that because I was supporting some formatters like this), but for std::forward_list, its summary provider will force the calculation of the size (because it prints the size in the summary).

For this, I think the fix is to change the formatter to *not* print the exact size (all the time). For example, it could call `GetNumChildren(X)` and if the result is smaller than `X`, it can print the exact size (`size=x`). Otherwise it can just print the lower bound (`size>=X` ?).

The value of `X` might be derived from the setting, but I think it'd also make sense have an independent constant, because not every client has to display the values according to this setting (for example, VSCode always prints the first 100 values).

https://github.com/llvm/llvm-project/pull/139805


More information about the lldb-commits mailing list