qmljs: add ImportsBenchmarker

To see the results use
QT_LOGGING_RULES=qtc.qmljs.imports.benchmark.*=true

Change-Id: I07fe7b71d893423f3dfe5f9c0f1410bd29312943
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Tim Jenssen
2021-01-05 17:41:35 +01:00
parent 0f4f67bc4e
commit e809f665e4

View File

@@ -32,11 +32,35 @@
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QCryptographicHash> #include <QCryptographicHash>
#include <QElapsedTimer>
#include <QLoggingCategory> #include <QLoggingCategory>
#include <algorithm> #include <algorithm>
static Q_LOGGING_CATEGORY(importsLog, "qtc.qmljs.imports", QtWarningMsg) static Q_LOGGING_CATEGORY(importsLog, "qtc.qmljs.imports", QtWarningMsg)
static Q_LOGGING_CATEGORY(importsBenchmark, "qtc.qmljs.imports.benchmark", QtDebugMsg)
class ImportsBenchmarker
{
public:
ImportsBenchmarker(const QString &functionName)
: m_functionName(functionName)
{
m_timer.start();
}
~ImportsBenchmarker()
{
if (importsBenchmark().isDebugEnabled()) {
qCDebug(importsBenchmark).noquote().nospace() << m_functionName << " executed nPossibleExports: " << nPossibleExports << " in " << m_timer.elapsed() << "ms";
}
}
int nPossibleExports = 0;
QElapsedTimer m_timer;
QString m_functionName;
};
namespace QmlJS { namespace QmlJS {
@@ -596,6 +620,7 @@ ImportDependencies::~ImportDependencies()
void ImportDependencies::filter(const ViewerContext &vContext) void ImportDependencies::filter(const ViewerContext &vContext)
{ {
ImportsBenchmarker benchMark("filter()");
QMap<QString, CoreImport> newCoreImports; QMap<QString, CoreImport> newCoreImports;
QMap<ImportKey, QStringList> newImportCache; QMap<ImportKey, QStringList> newImportCache;
bool hasChanges = false; bool hasChanges = false;
@@ -604,6 +629,7 @@ void ImportDependencies::filter(const ViewerContext &vContext)
if (languageIsCompatible(vContext.language, cImport.language)) { if (languageIsCompatible(vContext.language, cImport.language)) {
QList<Export> newExports; QList<Export> newExports;
foreach (const Export &e, cImport.possibleExports) { foreach (const Export &e, cImport.possibleExports) {
++benchMark.nPossibleExports;
if (e.visibleInVContext(vContext)) { if (e.visibleInVContext(vContext)) {
newExports.append(e); newExports.append(e);
QStringList &candidateImports = newImportCache[e.exportName]; QStringList &candidateImports = newImportCache[e.exportName];
@@ -641,6 +667,7 @@ void ImportDependencies::iterateOnCandidateImports(
std::function<bool (const ImportMatchStrength &,const Export &,const CoreImport &)> std::function<bool (const ImportMatchStrength &,const Export &,const CoreImport &)>
const &iterF) const const &iterF) const
{ {
ImportsBenchmarker benchMark("iterateOnCandidateImports()");
switch (key.type) { switch (key.type) {
case ImportType::Directory: case ImportType::Directory:
case ImportType::QrcDirectory: case ImportType::QrcDirectory:
@@ -653,6 +680,7 @@ void ImportDependencies::iterateOnCandidateImports(
CoreImport cImport = coreImport(cImportName); CoreImport cImport = coreImport(cImportName);
if (languageIsCompatible(vContext.language, cImport.language)) { if (languageIsCompatible(vContext.language, cImport.language)) {
foreach (const Export e, cImport.possibleExports) { foreach (const Export e, cImport.possibleExports) {
++benchMark.nPossibleExports;
if (e.visibleInVContext(vContext)) { if (e.visibleInVContext(vContext)) {
ImportMatchStrength m = e.exportName.matchImport(key, vContext); ImportMatchStrength m = e.exportName.matchImport(key, vContext);
if (m.hasMatch()) { if (m.hasMatch()) {
@@ -675,6 +703,7 @@ void ImportDependencies::iterateOnCandidateImports(
CoreImport cImport = coreImport(cImportName); CoreImport cImport = coreImport(cImportName);
if (languageIsCompatible(vContext.language, cImport.language)) { if (languageIsCompatible(vContext.language, cImport.language)) {
foreach (const Export e, cImport.possibleExports) { foreach (const Export e, cImport.possibleExports) {
++benchMark.nPossibleExports;
if (e.visibleInVContext(vContext)) { if (e.visibleInVContext(vContext)) {
ImportMatchStrength m = e.exportName.matchImport(key, vContext); ImportMatchStrength m = e.exportName.matchImport(key, vContext);
if (m.hasMatch()) { if (m.hasMatch()) {
@@ -840,6 +869,8 @@ void ImportDependencies::iterateOnLibraryImports(
const Export &, const Export &,
const CoreImport &)> const &iterF) const const CoreImport &)> const &iterF) const
{ {
ImportsBenchmarker benchMark("iterateOnLibraryImports()");
typedef QMap<ImportKey, QStringList>::const_iterator iter_t; typedef QMap<ImportKey, QStringList>::const_iterator iter_t;
ImportKey firstLib; ImportKey firstLib;
firstLib.type = ImportType::Library; firstLib.type = ImportType::Library;
@@ -851,6 +882,7 @@ void ImportDependencies::iterateOnLibraryImports(
CoreImport cImport = coreImport(cImportName); CoreImport cImport = coreImport(cImportName);
if (languageIsCompatible(vContext.language, cImport.language)) { if (languageIsCompatible(vContext.language, cImport.language)) {
foreach (const Export &e, cImport.possibleExports) { foreach (const Export &e, cImport.possibleExports) {
++benchMark.nPossibleExports;
if (e.visibleInVContext(vContext) && e.exportName.type == ImportType::Library) { if (e.visibleInVContext(vContext) && e.exportName.type == ImportType::Library) {
ImportMatchStrength m = e.exportName.matchImport(i.key(), vContext); ImportMatchStrength m = e.exportName.matchImport(i.key(), vContext);
if (m.hasMatch()) { if (m.hasMatch()) {
@@ -874,6 +906,7 @@ void ImportDependencies::iterateOnSubImports(
const Export &, const Export &,
const CoreImport &)> const &iterF) const const CoreImport &)> const &iterF) const
{ {
ImportsBenchmarker benchMark("iterateOnSubImports()");
typedef QMap<ImportKey, QStringList>::const_iterator iter_t; typedef QMap<ImportKey, QStringList>::const_iterator iter_t;
iter_t i = m_importCache.lowerBound(baseKey); iter_t i = m_importCache.lowerBound(baseKey);
iter_t end = m_importCache.constEnd(); iter_t end = m_importCache.constEnd();
@@ -885,6 +918,7 @@ void ImportDependencies::iterateOnSubImports(
CoreImport cImport = coreImport(cImportName); CoreImport cImport = coreImport(cImportName);
if (languageIsCompatible(vContext.language, cImport.language)) { if (languageIsCompatible(vContext.language, cImport.language)) {
foreach (const Export &e, cImport.possibleExports) { foreach (const Export &e, cImport.possibleExports) {
++benchMark.nPossibleExports;
if (e.visibleInVContext(vContext)) { if (e.visibleInVContext(vContext)) {
ImportMatchStrength m = e.exportName.matchImport(i.key(), vContext); ImportMatchStrength m = e.exportName.matchImport(i.key(), vContext);
if (m.hasMatch()) { if (m.hasMatch()) {