Skip to content

Commit b6bf27e

Browse files
jeffreytan81jeffreytan81
and
jeffreytan81
authored
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@fb.com>
1 parent 02d8813 commit b6bf27e

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

lldb/examples/synthetic/gnu_libstdcpp.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -473,11 +473,7 @@ def get_child_at_index(self, index):
473473
"[" + str(index) + "]", element_offset, element_type
474474
)
475475
bit = element.GetValueAsUnsigned(0) & (1 << bit_offset)
476-
if bit != 0:
477-
value_expr = "(bool)true"
478-
else:
479-
value_expr = "(bool)false"
480-
return self.valobj.CreateValueFromExpression("[%d]" % index, value_expr)
476+
return self.valobj.CreateBoolValue("[%d]" % index, bool(bit))
481477

482478
def update(self):
483479
try:

lldb/include/lldb/API/SBValue.h

+2
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ class LLDB_API SBValue {
145145
// AddressOf() on the return of this call all return invalid
146146
lldb::SBValue CreateValueFromData(const char *name, lldb::SBData data,
147147
lldb::SBType type);
148+
// Returned value has no address.
149+
lldb::SBValue CreateBoolValue(const char *name, bool value);
148150

149151
/// Get a child value by index from a value.
150152
///

lldb/source/API/SBValue.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,22 @@ lldb::SBValue SBValue::CreateValueFromData(const char *name, SBData data,
645645
return sb_value;
646646
}
647647

648+
lldb::SBValue SBValue::CreateBoolValue(const char *name, bool value) {
649+
LLDB_INSTRUMENT_VA(this, name);
650+
651+
lldb::SBValue sb_value;
652+
lldb::ValueObjectSP new_value_sp;
653+
ValueLocker locker;
654+
lldb::ValueObjectSP value_sp(GetSP(locker));
655+
lldb::TargetSP target_sp = m_opaque_sp->GetTargetSP();
656+
if (value_sp && target_sp) {
657+
new_value_sp =
658+
ValueObject::CreateValueObjectFromBool(target_sp, value, name);
659+
}
660+
sb_value.SetSP(new_value_sp);
661+
return sb_value;
662+
}
663+
648664
SBValue SBValue::GetChildAtIndex(uint32_t idx) {
649665
LLDB_INSTRUMENT_VA(this, idx);
650666

0 commit comments

Comments
 (0)