From fdaa9b1c10d9a57ca4195bb4337e0cf93c4a356c Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Fri, 13 Aug 2021 10:35:49 +0200 Subject: [PATCH] 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 Reviewed-by: Qt CI Bot --- src/libs/qmljs/qmljsmodelmanagerinterface.cpp | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/libs/qmljs/qmljsmodelmanagerinterface.cpp b/src/libs/qmljs/qmljsmodelmanagerinterface.cpp index d0d1d211382..34048e81850 100644 --- a/src/libs/qmljs/qmljsmodelmanagerinterface.cpp +++ b/src/libs/qmljs/qmljsmodelmanagerinterface.cpp @@ -977,16 +977,21 @@ void ModelManagerInterface::parseLoop(QSet &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; - findNewImplicitImports(doc, snapshot, &importedFiles, &scannedPaths); - findNewFileImports(doc, snapshot, &importedFiles, &scannedPaths); - findNewLibraryImports(doc, snapshot, modelManager, &importedFiles, &scannedPaths, - &newLibraries); + + // 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)) {