QmlJS: Destroy local snapshot before modifying its original

If we keep the copy of the snapshot around while it's being modified, we
trigger the copy-on-write mechanism. That is expensive, and destroying
the snapshot afterwards is also expensive.

Task-number: QTCREATORBUG-25899
Change-Id: I9b7e26baf63a4b47c85457e5657fee971a6ce132
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Ulf Hermann
2021-08-13 10:35:49 +02:00
parent a6917a5484
commit fdaa9b1c10

View File

@@ -977,16 +977,21 @@ void ModelManagerInterface::parseLoop(QSet<QString> &scannedPaths,
}
}
#endif
// update snapshot. requires synchronization, but significantly reduces amount of file
// system queries for library imports because queries are cached in libraryInfo
const Snapshot snapshot = modelManager->snapshot();
// get list of referenced files not yet in snapshot or in directories already scanned
QStringList importedFiles;
// update snapshot. requires synchronization, but significantly reduces amount of file
// system queries for library imports because queries are cached in libraryInfo
{
// Make sure the snapshot is destroyed before updateDocument, so that we don't trigger
// the copy-on-write mechanism on its internals.
const Snapshot snapshot = modelManager->snapshot();
findNewImplicitImports(doc, snapshot, &importedFiles, &scannedPaths);
findNewFileImports(doc, snapshot, &importedFiles, &scannedPaths);
findNewLibraryImports(doc, snapshot, modelManager, &importedFiles, &scannedPaths,
&newLibraries);
}
// add new files to parse list
for (const QString &file : qAsConst(importedFiles)) {