[Lldb-commits] [lldb] b6bf27e - Avoid expression evaluation in libStdC++ std::vector<bool> synthetic children provider (#108414)
via lldb-commits
lldb-commits at lists.llvm.org
Fri Sep 13 10:26:04 PDT 2024
Author: jeffreytan81
Date: 2024-09-13T10:26:01-07:00
New Revision: b6bf27ef3c179eefd805f39aa681705fc980ceed
URL: https://github.com/llvm/llvm-project/commit/b6bf27ef3c179eefd805f39aa681705fc980ceed
DIFF: https://github.com/llvm/llvm-project/commit/b6bf27ef3c179eefd805f39aa681705fc980ceed.diff
LOG: Avoid expression evaluation in libStdC++ std::vector<bool> synthetic children provider (#108414)
Our customers is reporting a serious performance issue (expanding a this
pointer takes 70 seconds in VSCode) in a specific execution context.
Profiling shows the hot path is triggered by an expression evaluation
from libStdC++ synthetic children provider for `std::vector<bool>` since
it uses `CreateValueFromExpression()`.
This PR added a new `SBValue::CreateBoolValue()` API and switch
`std::vector<bool>` synthetic children provider to use the new API
without performing expression evaluation.
Note: there might be other cases of `CreateValueFromExpression()` in our
summary/synthetic children providers which I will sweep through in later
PRs.
With this PR, the customer's scenario reduces from 70 seconds => 50
seconds. I will add other PRs to further optimize the remaining 50
seconds (mostly from type/namespace lookup).
Testing:
`test/API/functionalities/data-formatter/data-formatter-stl/libstdcpp/vbool/TestDataFormatterStdVBool.py`
passes with the PR
---------
Co-authored-by: jeffreytan81 <jeffreytan at fb.com>
Added:
Modified:
lldb/examples/synthetic/gnu_libstdcpp.py
lldb/include/lldb/API/SBValue.h
lldb/source/API/SBValue.cpp
Removed:
################################################################################
diff --git a/lldb/examples/synthetic/gnu_libstdcpp.py b/lldb/examples/synthetic/gnu_libstdcpp.py
index d98495b8a9df38..a6605a7a7eb5b3 100644
--- a/lldb/examples/synthetic/gnu_libstdcpp.py
+++ b/lldb/examples/synthetic/gnu_libstdcpp.py
@@ -473,11 +473,7 @@ def get_child_at_index(self, index):
"[" + str(index) + "]", element_offset, element_type
)
bit = element.GetValueAsUnsigned(0) & (1 << bit_offset)
- if bit != 0:
- value_expr = "(bool)true"
- else:
- value_expr = "(bool)false"
- return self.valobj.CreateValueFromExpression("[%d]" % index, value_expr)
+ return self.valobj.CreateBoolValue("[%d]" % index, bool(bit))
def update(self):
try:
diff --git a/lldb/include/lldb/API/SBValue.h b/lldb/include/lldb/API/SBValue.h
index bec816fb451844..9090cece80f7ce 100644
--- a/lldb/include/lldb/API/SBValue.h
+++ b/lldb/include/lldb/API/SBValue.h
@@ -145,6 +145,8 @@ class LLDB_API SBValue {
// AddressOf() on the return of this call all return invalid
lldb::SBValue CreateValueFromData(const char *name, lldb::SBData data,
lldb::SBType type);
+ // Returned value has no address.
+ lldb::SBValue CreateBoolValue(const char *name, bool value);
/// Get a child value by index from a value.
///
diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index 273aac5ad47989..e1a31708d46ffb 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -645,6 +645,22 @@ lldb::SBValue SBValue::CreateValueFromData(const char *name, SBData data,
return sb_value;
}
+lldb::SBValue SBValue::CreateBoolValue(const char *name, bool value) {
+ LLDB_INSTRUMENT_VA(this, name);
+
+ lldb::SBValue sb_value;
+ lldb::ValueObjectSP new_value_sp;
+ ValueLocker locker;
+ lldb::ValueObjectSP value_sp(GetSP(locker));
+ lldb::TargetSP target_sp = m_opaque_sp->GetTargetSP();
+ if (value_sp && target_sp) {
+ new_value_sp =
+ ValueObject::CreateValueObjectFromBool(target_sp, value, name);
+ }
+ sb_value.SetSP(new_value_sp);
+ return sb_value;
+}
+
SBValue SBValue::GetChildAtIndex(uint32_t idx) {
LLDB_INSTRUMENT_VA(this, idx);
More information about the lldb-commits
mailing list