diff --git a/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java b/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java index 49fbce020330..7d2ceea1b4b5 100644 --- a/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java +++ b/platform/platform-impl/src/com/intellij/ide/RecentProjectsManagerBase.java @@ -99,6 +99,8 @@ public abstract class RecentProjectsManagerBase extends RecentProjectsManager im private State myState = new State(); private final Map myNameCache = Collections.synchronizedMap(new THashMap()); + private Set myDuplicatesCache = null; + private boolean isDuplicatesCacheUpdating = false; protected RecentProjectsManagerBase(@NotNull MessageBus messageBus) { MessageBusConnection connection = messageBus.connect(); @@ -328,14 +330,28 @@ public abstract class RecentProjectsManagerBase extends RecentProjectsManager im } private Set getDuplicateProjectNames(Set openedPaths, Set recentPaths) { - Set names = ContainerUtil.newHashSet(); - Set duplicates = ContainerUtil.newHashSet(); - for (String path : ContainerUtil.concat(openedPaths, recentPaths)) { - if (!names.add(getProjectName(path))) { - duplicates.add(path); - } + if (myDuplicatesCache != null) { + return myDuplicatesCache; } - return duplicates; + + if (!isDuplicatesCacheUpdating) { + isDuplicatesCacheUpdating = true; //assuming that this check happens only on EDT. So, no synchronised block or double-checked locking needed + ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { + @Override + public void run() { + Set names = ContainerUtil.newHashSet(); + final HashSet duplicates = ContainerUtil.newHashSet(); + for (String path : ContainerUtil.concat(openedPaths, recentPaths)) { + if (!names.add(getProjectName(path))) { + duplicates.add(path); + } + } + myDuplicatesCache = duplicates; + isDuplicatesCacheUpdating = false; + } + }); + } + return ContainerUtil.newHashSet(); } @Override