From 050be8ebe15667e9c7bc7530db8af0373e81a064 Mon Sep 17 00:00:00 2001 From: Marc-Andre Laperle Date: Sat, 5 Sep 2020 22:25:34 -0400 Subject: [PATCH] Bug 565553 - Improve performance of build command parsers with large number of files Optimize AbstractLanguageSettingsOutputScanner.findResource by checking under the currentProject first when searching for the IFile corresponding to the parsed file name. When the parsed file name is absolute, we can try to make it relative to the current project and see if it exists as an IFile instead of going through findFilesForLocationURI which is very slow. Having an absolute path for the source file is quite common under the current (local) projet. This saves around 1.5 sec when parsing all commands of LLVM projet as an example. Change-Id: I576a917410e5d5ecbd8e932011555c699b250354 Signed-off-by: Marc-Andre Laperle --- .../AbstractLanguageSettingsOutputScanner.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractLanguageSettingsOutputScanner.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractLanguageSettingsOutputScanner.java index 854c38a1052..56ac320955e 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractLanguageSettingsOutputScanner.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractLanguageSettingsOutputScanner.java @@ -48,6 +48,7 @@ import org.eclipse.cdt.utils.EFSExtensionManager; import org.eclipse.cdt.utils.cdtvariables.CdtVariableResolver; import org.eclipse.core.filesystem.EFS; import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; @@ -757,7 +758,20 @@ public abstract class AbstractLanguageSettingsOutputScanner extends LanguageSett } // try to find absolute path in the workspace - if (sourceFile == null && new Path(parsedResourceName).isAbsolute()) { + Path parsedPath = new Path(parsedResourceName); + if (sourceFile == null && parsedPath.isAbsolute()) { + // It will often happen that the file will be under the project and in the local file system, so check there first. + IPath projectLocation = currentProject != null ? currentProject.getLocation() : null; + if (projectLocation != null) { + IPath relativePath = parsedPath.makeRelativeTo(projectLocation); + if (!relativePath.equals(parsedPath)) { + IFile file = currentProject.getFile(relativePath); + if (file.isAccessible()) { + return file; + } + } + } + URI uri = org.eclipse.core.filesystem.URIUtil.toURI(parsedResourceName); sourceFile = findFileForLocationURI(uri, currentProject, /*checkExistence*/ true); }