diff options
author | Nikolai Kosjar <nikolai.kosjar@qt.io> | 2017-02-06 16:59:53 +0100 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@qt.io> | 2017-02-20 09:18:13 +0000 |
commit | 8c90998fff6ec3cf85ad87b56175e86b6f0a93d0 (patch) | |
tree | c3f838d24e4cd7c3484c5a50d1f07a5b73de5bf9 /src/plugins/genericprojectmanager | |
parent | 010060de5c205a79dba0343ef82f10f3446c1e58 (diff) | |
download | qt-creator-8c90998fff6ec3cf85ad87b56175e86b6f0a93d0.tar.gz |
CppTools/ProjectManagers: Reduce ui blocking when loading projects
${AnyProject}::updateCppCodeModel() did two potentially not that cheap
operations in the ui thread:
(1) Querying the MimeDatabase for the mime type for the source files of
the project. In 99.9% of the cases no files need to be read for
this as the file extension will resolve the type. The expensiveness
comes from the sheer number of files that can occur.
(2) Calling compilers with the "(sub)project's compiler command line"
to determine the macros. While the caches avoid redundant calls,
the number of the unique compiler calls makes this still a
ui-freezing experience.
These two operations are moved into a worker thread. For this, the
expensive compiler calls are encapsulated in thread safe lambdas
("runners") in order to keep the "mutexed" data minimal. The original
API calls of the toolchains are implemented in terms of the runners.
While adapting the project managers, remove also the calls to
setProjectLanguage(). These are redundant because all of the project
managers already set a proper value in the constructor. Also, currently
there is no need (client) to report back detection of C sources in
project parts. This also keeps CppProjectUpdater simple.
There is still room for improvement:
* Run the compiler calls in parallel instead of sequence.
* Ensure that the mime type for a file is determined exactly once.
Change-Id: I2efc4e132ee88e3c8f264012ec8fafe3d86c404f
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
Diffstat (limited to 'src/plugins/genericprojectmanager')
-rw-r--r-- | src/plugins/genericprojectmanager/genericproject.cpp | 37 | ||||
-rw-r--r-- | src/plugins/genericprojectmanager/genericproject.h | 4 |
2 files changed, 25 insertions, 16 deletions
diff --git a/src/plugins/genericprojectmanager/genericproject.cpp b/src/plugins/genericprojectmanager/genericproject.cpp index a06a6fba10..a6d3bff6a7 100644 --- a/src/plugins/genericprojectmanager/genericproject.cpp +++ b/src/plugins/genericprojectmanager/genericproject.cpp @@ -35,7 +35,7 @@ #include <cpptools/cpptoolsconstants.h> #include <cpptools/cppmodelmanager.h> #include <cpptools/projectinfo.h> -#include <cpptools/projectpartbuilder.h> +#include <cpptools/cppprojectupdater.h> #include <extensionsystem/pluginmanager.h> #include <projectexplorer/abi.h> #include <projectexplorer/buildsteplist.h> @@ -66,6 +66,7 @@ namespace Internal { //////////////////////////////////////////////////////////////////////////////////// GenericProject::GenericProject(Manager *manager, const QString &fileName) + : m_cppCodeModelUpdater(new CppTools::CppProjectUpdater(this)) { setId(Constants::GENERICPROJECT_ID); setProjectManager(manager); @@ -96,7 +97,7 @@ GenericProject::GenericProject(Manager *manager, const QString &fileName) GenericProject::~GenericProject() { - m_codeModelFuture.cancel(); + delete m_cppCodeModelUpdater; projectManager()->unregisterProject(this); } @@ -338,12 +339,19 @@ QStringList GenericProject::processEntries(const QStringList &paths, void GenericProject::refreshCppCodeModel() { - CppTools::CppModelManager *modelManager = CppTools::CppModelManager::instance(); + const Kit *k = nullptr; + if (Target *target = activeTarget()) + k = target->kit(); + else + k = KitManager::defaultKit(); + QTC_ASSERT(k, return); - m_codeModelFuture.cancel(); + ToolChain *cToolChain + = ToolChainKitInformation::toolChain(k, ProjectExplorer::Constants::C_LANGUAGE_ID); + ToolChain *cxxToolChain + = ToolChainKitInformation::toolChain(k, ProjectExplorer::Constants::CXX_LANGUAGE_ID); - CppTools::ProjectInfo pInfo(this); - CppTools::ProjectPartBuilder ppBuilder(pInfo); + m_cppCodeModelUpdater->cancel(); CppTools::ProjectPart::QtVersion activeQtVersion = CppTools::ProjectPart::NoQt; if (QtSupport::BaseQtVersion *qtVersion = @@ -354,16 +362,15 @@ void GenericProject::refreshCppCodeModel() activeQtVersion = CppTools::ProjectPart::Qt5; } - ppBuilder.setProjectFile(projectFilePath().toString()); - ppBuilder.setQtVersion(activeQtVersion); - ppBuilder.setIncludePaths(projectIncludePaths()); - ppBuilder.setConfigFileName(configFileName()); + CppTools::RawProjectPart rpp; + rpp.setProjectFile(projectFilePath().toString()); + rpp.setQtVersion(activeQtVersion); + rpp.setIncludePaths(projectIncludePaths()); + rpp.setConfigFileName(configFileName()); + rpp.setFiles(files()); - const QList<Id> languages = ppBuilder.createProjectPartsForFiles(files()); - for (Id language : languages) - setProjectLanguage(language, true); - - m_codeModelFuture = modelManager->updateProjectInfo(pInfo); + const CppTools::ProjectUpdateInfo projectInfoUpdate(this, cToolChain, cxxToolChain, k, {rpp}); + m_cppCodeModelUpdater->update(projectInfoUpdate); } void GenericProject::activeTargetWasChanged() diff --git a/src/plugins/genericprojectmanager/genericproject.h b/src/plugins/genericprojectmanager/genericproject.h index 59655c39cd..815f8024b0 100644 --- a/src/plugins/genericprojectmanager/genericproject.h +++ b/src/plugins/genericprojectmanager/genericproject.h @@ -37,6 +37,8 @@ #include <QFuture> +namespace CppTools { class CppProjectUpdater; } + namespace GenericProjectManager { namespace Internal { @@ -104,7 +106,7 @@ private: QStringList m_rawProjectIncludePaths; QStringList m_projectIncludePaths; - QFuture<void> m_codeModelFuture; + CppTools::CppProjectUpdater *m_cppCodeModelUpdater = nullptr; ProjectExplorer::Target *m_activeTarget = nullptr; }; |