Commit 296be522 authored by kozyatinskiy's avatar kozyatinskiy Committed by Commit bot

[inspector] collect old async stack traces 20% faster

BUG=v8:6189
R=dgozman@chromium.org

Review-Url: https://codereview.chromium.org/2826183002
Cr-Commit-Position: refs/heads/master@{#44755}
parent f4721a5f
......@@ -133,6 +133,17 @@ v8::MaybeLocal<v8::Object> generatorObjectLocation(
suspendedLocation.GetColumnNumber());
}
template <typename Map>
void cleanupExpiredWeakPointers(Map& map) {
for (auto it = map.begin(); it != map.end();) {
if (it->second.expired()) {
it = map.erase(it);
} else {
++it;
}
}
}
} // namespace
static bool inLiveEditScope = false;
......@@ -1017,36 +1028,24 @@ void V8Debugger::collectOldAsyncStacksIfNeeded() {
m_allAsyncStacks.pop_front();
--m_asyncStacksCount;
}
removeOldAsyncTasks(m_asyncTaskStacks);
removeOldAsyncTasks(m_asyncTaskCreationStacks);
protocol::HashSet<void*> recurringLeft;
for (auto task : m_recurringTasks) {
if (m_asyncTaskStacks.find(task) == m_asyncTaskStacks.end()) continue;
recurringLeft.insert(task);
cleanupExpiredWeakPointers(m_asyncTaskStacks);
cleanupExpiredWeakPointers(m_asyncTaskCreationStacks);
for (auto it = m_recurringTasks.begin(); it != m_recurringTasks.end();) {
if (m_asyncTaskStacks.find(*it) == m_asyncTaskStacks.end()) {
it = m_recurringTasks.erase(it);
} else {
++it;
}
}
m_recurringTasks.swap(recurringLeft);
protocol::HashMap<void*, void*> parentLeft;
for (auto it : m_parentTask) {
if (m_asyncTaskCreationStacks.find(it.second) ==
for (auto it = m_parentTask.begin(); it != m_parentTask.end();) {
if (m_asyncTaskCreationStacks.find(it->second) ==
m_asyncTaskCreationStacks.end()) {
continue;
it = m_parentTask.erase(it);
} else {
++it;
}
parentLeft.insert(it);
}
m_parentTask.swap(parentLeft);
std::map<int, std::weak_ptr<StackFrame>> framesCache;
for (auto it : m_framesCache) {
if (!it.second.expired()) framesCache.insert(it);
}
m_framesCache.swap(framesCache);
}
void V8Debugger::removeOldAsyncTasks(AsyncTaskToStackTrace& map) {
AsyncTaskToStackTrace cleanCopy;
for (auto it : map) {
if (!it.second.expired()) cleanCopy.insert(it);
}
map.swap(cleanCopy);
cleanupExpiredWeakPointers(m_framesCache);
}
std::shared_ptr<StackFrame> V8Debugger::symbolize(
......
......@@ -200,7 +200,6 @@ class V8Debugger : public v8::debug::DebugDelegate {
std::vector<std::shared_ptr<AsyncStackTrace>> m_currentAsyncCreation;
void collectOldAsyncStacksIfNeeded();
void removeOldAsyncTasks(AsyncTaskToStackTrace& map);
int m_asyncStacksCount = 0;
// V8Debugger owns all the async stacks, while most of the other references
// are weak, which allows to collect some stacks when there are too many.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment