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/cpptools/cppprojectupdater.h | |
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/cpptools/cppprojectupdater.h')
-rw-r--r-- | src/plugins/cpptools/cppprojectupdater.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/plugins/cpptools/cppprojectupdater.h b/src/plugins/cpptools/cppprojectupdater.h new file mode 100644 index 0000000000..60e470b0f7 --- /dev/null +++ b/src/plugins/cpptools/cppprojectupdater.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#pragma once + +#include "cpptools_global.h" +#include "projectinfo.h" + +#include <projectexplorer/project.h> + +#include <QFutureInterface> +#include <QFutureWatcher> + +namespace CppTools { + +class ProjectInfo; +class ProjectUpdateInfo; + +class CPPTOOLS_EXPORT CppProjectUpdater : public QObject +{ + Q_OBJECT + +public: + CppProjectUpdater(ProjectExplorer::Project *project); + ~CppProjectUpdater(); + + void update(const ProjectUpdateInfo &projectUpdateInfo); + void cancel(); + +signals: + void projectInfoUpdated(const ProjectInfo &projectInfo); + +private: + void cancelAndWaitForFinished(); + + void onToolChainRemoved(ProjectExplorer::ToolChain *); + void onProjectInfoGenerated(); + +private: + ProjectExplorer::Project * const m_project; + ProjectUpdateInfo m_projectUpdateInfo; + + QFutureInterface<void> m_futureInterface; + QFutureWatcher<ProjectInfo> m_generateFutureWatcher; +}; + +} // namespace CppTools |