Skip to content

Commit 9faf8b5

Browse files
author
jeffreytan81
authored
Lazy deference underlying object for shared/weak/unique_ptr synthetic… (#67069)
We noticed some performance issue while in lldb-vscode for grabing the name of the SBValue. Profiling shows SBValue::GetName() can cause synthetic children provider of shared/unique_ptr to deference underlying object and complete it type. This patch lazily moves the dereference from synthetic child provider's Update() method to GetChildAtIndex() so that SBValue::GetName() won't trigger the slow code path. Here is the culprit slow code path: ``` ... frame #59: 0x00007ff4102e0660 liblldb.so.15`SymbolFileDWARF::CompleteType(this=<unavailable>, compiler_type=0x00007ffdd9829450) at SymbolFileDWARF.cpp:1567:25 [opt] ... frame #67: 0x00007ff40fdf9bd4 liblldb.so.15`lldb_private::ValueObject::Dereference(this=0x0000022bb5dfe980, error=0x00007ffdd9829970) at ValueObject.cpp:2672:41 [opt] frame #68: 0x00007ff41011bb0a liblldb.so.15`(anonymous namespace)::LibStdcppSharedPtrSyntheticFrontEnd::Update(this=0x000002298fb94380) at LibStdcpp.cpp:403:40 [opt] frame #69: 0x00007ff41011af9a liblldb.so.15`lldb_private::formatters::LibStdcppSharedPtrSyntheticFrontEndCreator(lldb_private::CXXSyntheticChildren*, std::shared_ptr<lldb_private::ValueObject>) [inlined] (anonymous namespace)::LibStdcppSharedPtrSyntheticFrontEnd::LibStdcppSharedPtrSyntheticFrontEnd(this=0x000002298fb94380, valobj_sp=<unavailable>) at LibStdcpp.cpp:371:5 [opt] ... frame #78: 0x00007ff40fdf6e42 liblldb.so.15`lldb_private::ValueObject::CalculateSyntheticValue(this=0x000002296c66a500) at ValueObject.cpp:1836:27 [opt] frame #79: 0x00007ff40fdf1939 liblldb.so.15`lldb_private::ValueObject::GetSyntheticValue(this=<unavailable>) at ValueObject.cpp:1867:3 [opt] frame #80: 0x00007ff40fc89008 liblldb.so.15`ValueImpl::GetSP(this=0x0000022c71b90de0, stop_locker=0x00007ffdd9829d00, lock=0x00007ffdd9829d08, error=0x00007ffdd9829d18) at SBValue.cpp:141:46 [opt] frame #81: 0x00007ff40fc7d82a liblldb.so.15`lldb::SBValue::GetSP(ValueLocker&) const [inlined] ValueLocker::GetLockedSP(this=0x00007ffdd9829d00, in_value=<unavailable>) at SBValue.cpp:208:21 [opt] frame #82: 0x00007ff40fc7d817 liblldb.so.15`lldb::SBValue::GetSP(this=0x00007ffdd9829d90, locker=0x00007ffdd9829d00) const at SBValue.cpp:1047:17 [opt] frame #83: 0x00007ff40fc7da6f liblldb.so.15`lldb::SBValue::GetName(this=0x00007ffdd9829d90) at SBValue.cpp:294:32 [opt] ... ``` Differential Revision: https://reviews.llvm.org/D159542
1 parent 7421040 commit 9faf8b5

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

lldb/source/Plugins/Language/CPlusPlus/LibStdcpp.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,16 @@ lldb::ValueObjectSP
377377
LibStdcppSharedPtrSyntheticFrontEnd::GetChildAtIndex(size_t idx) {
378378
if (idx == 0)
379379
return m_ptr_obj->GetSP();
380-
if (idx == 1)
381-
return m_obj_obj->GetSP();
382-
380+
if (idx == 1) {
381+
if (m_ptr_obj && !m_obj_obj) {
382+
Status error;
383+
ValueObjectSP obj_obj = m_ptr_obj->Dereference(error);
384+
if (error.Success())
385+
m_obj_obj = obj_obj->Clone(ConstString("object")).get();
386+
}
387+
if (m_obj_obj)
388+
return m_obj_obj->GetSP();
389+
}
383390
return lldb::ValueObjectSP();
384391
}
385392

@@ -397,14 +404,7 @@ bool LibStdcppSharedPtrSyntheticFrontEnd::Update() {
397404
return false;
398405

399406
m_ptr_obj = ptr_obj_sp->Clone(ConstString("pointer")).get();
400-
401-
if (m_ptr_obj) {
402-
Status error;
403-
ValueObjectSP obj_obj = m_ptr_obj->Dereference(error);
404-
if (error.Success()) {
405-
m_obj_obj = obj_obj->Clone(ConstString("object")).get();
406-
}
407-
}
407+
m_obj_obj = nullptr;
408408

409409
return false;
410410
}

lldb/source/Plugins/Language/CPlusPlus/LibStdcppUniquePointer.cpp

+12-10
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,7 @@ bool LibStdcppUniquePtrSyntheticFrontEnd::Update() {
108108
if (del_obj)
109109
m_del_obj = del_obj->Clone(ConstString("deleter")).get();
110110
}
111-
112-
if (m_ptr_obj) {
113-
Status error;
114-
ValueObjectSP obj_obj = m_ptr_obj->Dereference(error);
115-
if (error.Success()) {
116-
m_obj_obj = obj_obj->Clone(ConstString("object")).get();
117-
}
118-
}
111+
m_obj_obj = nullptr;
119112

120113
return false;
121114
}
@@ -128,8 +121,17 @@ LibStdcppUniquePtrSyntheticFrontEnd::GetChildAtIndex(size_t idx) {
128121
return m_ptr_obj->GetSP();
129122
if (idx == 1 && m_del_obj)
130123
return m_del_obj->GetSP();
131-
if (idx == 2 && m_obj_obj)
132-
return m_obj_obj->GetSP();
124+
if (idx == 2) {
125+
if (m_ptr_obj && !m_obj_obj) {
126+
Status error;
127+
ValueObjectSP obj_obj = m_ptr_obj->Dereference(error);
128+
if (error.Success()) {
129+
m_obj_obj = obj_obj->Clone(ConstString("object")).get();
130+
}
131+
}
132+
if (m_obj_obj)
133+
return m_obj_obj->GetSP();
134+
}
133135
return lldb::ValueObjectSP();
134136
}
135137

0 commit comments

Comments
 (0)