From 55e9026881538c126293b7e682d0d147984254f1 Mon Sep 17 00:00:00 2001 From: Siew Yi Liang Date: Mon, 22 Jan 2024 11:16:47 -0800 Subject: [PATCH] Optimize compilation-find-file-projectile-find-compilation-buffer (#1874) If the target file already exists, navigate to it directly instead of running the expensive extra logic. --- CHANGELOG.md | 1 + projectile.el | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b45450c6..56a3b0813 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### New features +* [#1874](https://github.com/bbatsov/projectile/pull/1874): Changes `compilation-find-file-projectile-find-compilation-buffer` to navigate directly to the file if already present on disk to help improve performance in scenarios where there are a large number of project directories. * [#1870](https://github.com/bbatsov/projectile/pull/1870): Add package command for CMake projects. * [#1875](https://github.com/bbatsov/projectile/pull/1875): Add support for Sapling VCS. * [#1876](https://github.com/bbatsov/projectile/pull/1876): Add support for Jujutsu VCS. diff --git a/projectile.el b/projectile.el index b7f794f9a..5d030dc95 100644 --- a/projectile.el +++ b/projectile.el @@ -5406,14 +5406,18 @@ We enhance its functionality by appending the current project's directories to its search path. This way when filenames in compilation buffers can't be found by compilation's normal logic they are searched for in project directories." - (let* ((root (projectile-project-root)) - (compilation-search-path - (if (projectile-project-p) - (append compilation-search-path (list root) - (mapcar (lambda (f) (expand-file-name f root)) - (projectile-current-project-dirs))) - compilation-search-path))) - (apply orig-fun `(,marker ,filename ,directory ,@formats)))) + ; If the file already exists, don't bother running the extra logic as the project directories might be massive (i.e. Unreal-sized). + (if (file-exists-p filename) + (apply orig-fun `(,marker ,filename ,directory ,@formats)) + + (let* ((root (projectile-project-root)) + (compilation-search-path + (if (projectile-project-p) + (append compilation-search-path (list root) + (mapcar (lambda (f) (expand-file-name f root)) + (projectile-current-project-dirs))) + compilation-search-path))) + (apply orig-fun `(,marker ,filename ,directory ,@formats))))) (defun projectile-open-projects () "Return a list of all open projects.