From dc503d46fbb688bf29abf609e197346279c31963 Mon Sep 17 00:00:00 2001 From: Ivan Migalev Date: Tue, 10 Jun 2025 21:15:00 +0200 Subject: [PATCH] (JBR-8965) PluginPathManager: work around performance degradation java.io rerouted through java.nio causes performance degradations sometimes, because it relies on throwing and catching exceptions e.g. for checking File::isDirectory. This commit reduces the corresponding costs in the PluginPathManager somewhat by not triggering the same slow IO operations for multiple times. GitOrigin-RevId: fe4e70ea46eff352ee12f5b361c59e96b36b8cc9 --- .../openapi/application/PluginPathManager.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/application/PluginPathManager.java b/platform/platform-impl/src/com/intellij/openapi/application/PluginPathManager.java index f0fcee030a36..3aa4edf21b64 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/PluginPathManager.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/PluginPathManager.java @@ -1,4 +1,4 @@ -// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.application; import com.intellij.ide.plugins.PluginManagerCoreKt; @@ -12,6 +12,8 @@ import java.io.File; import java.net.URL; import java.nio.file.Path; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; public final class PluginPathManager { private PluginPathManager() { @@ -59,18 +61,20 @@ public final class PluginPathManager { } } + private static ConcurrentMap ourPluginHomes = new ConcurrentHashMap<>(); + public static File getPluginHome(@NonNls String pluginName) { - File subRepo = findSubRepo(pluginName); - if (subRepo != null) { - return subRepo; - } - return new File(PathManager.getHomePath(), "plugins/" + pluginName); + File subRepo = ourPluginHomes.computeIfAbsent(pluginName, k -> { + File repo = findSubRepo(k); + return repo != null ? repo : new File(PathManager.getHomePath(), "plugins/" + k); + }); + return subRepo; } private static File findSubRepo(String pluginName) { for (File subRepo : SubRepoHolder.subRepos) { File candidate = new File(subRepo, pluginName); - if (candidate.isDirectory()) { + if (candidate.exists() && candidate.isDirectory()) { return candidate; } }