From dc2ecf7cd84a7009480a6061409b68c9ee170700 Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 9 Jan 2015 19:01:28 +0100 Subject: [PATCH] IDEA-134002 IDE very slow after file movements --- .../openapi/vfs/newvfs/impl/VfsData.java | 16 +++---- .../newvfs/impl/VirtualFileSystemEntry.java | 4 +- .../com/intellij/openapi/vfs/VfsUtilTest.java | 46 +++++++++++++++++++ 3 files changed, 54 insertions(+), 12 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VfsData.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VfsData.java index ff42529f9bc6..cc08676659e9 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VfsData.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VfsData.java @@ -20,7 +20,6 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.vfs.InvalidVirtualFileAccessException; import com.intellij.openapi.vfs.newvfs.persistent.FSRecords; import com.intellij.util.ArrayUtil; -import com.intellij.util.SmartFMap; import com.intellij.util.concurrency.AtomicFieldUpdater; import com.intellij.util.containers.ConcurrentBitSet; import com.intellij.util.containers.ConcurrentIntObjectMap; @@ -82,7 +81,7 @@ public class VfsData { private static final ConcurrentIntObjectMap ourSegments = ContainerUtil.createConcurrentIntObjectMap(); private static final ConcurrentBitSet ourInvalidatedIds = new ConcurrentBitSet(); private static TIntHashSet ourDyingIds = new TIntHashSet(); - private static volatile SmartFMap ourChangedParents = SmartFMap.emptyMap(); + private static final ConcurrentIntObjectMap ourChangedParents = ContainerUtil.createConcurrentIntObjectMap(); static { ApplicationManager.getApplication().addApplicationListener(new ApplicationAdapter() { @@ -102,7 +101,7 @@ public class VfsData { if (!ourDyingIds.isEmpty()) { for (int id : ourDyingIds.toArray()) { assertNotNull(getSegment(id, false)).myObjectArray.set(getOffset(id), ourDeadMarker); - ourChangedParents = ourChangedParents.minus(new VirtualFileImpl(id, null, null)); + ourChangedParents.remove(id); } ourDyingIds = new TIntHashSet(); } @@ -165,15 +164,12 @@ public class VfsData { } @Nullable - static VirtualDirectoryImpl getChangedParent(VirtualFileSystemEntry child) { - SmartFMap map = ourChangedParents; - return map == (SmartFMap)SmartFMap.emptyMap() ? null : map.get(child); + static VirtualDirectoryImpl getChangedParent(int id) { + return ourChangedParents.get(id); } - static void changeParent(VirtualFileSystemEntry child, VirtualDirectoryImpl parent) { - synchronized (ourDeadMarker) { - ourChangedParents = ourChangedParents.plus(child, parent); - } + static void changeParent(int id, VirtualDirectoryImpl parent) { + ourChangedParents.put(id, parent); } static void invalidateFile(int id) { diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileSystemEntry.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileSystemEntry.java index 0365a653420e..e9e93327ac1c 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileSystemEntry.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualFileSystemEntry.java @@ -102,7 +102,7 @@ public abstract class VirtualFileSystemEntry extends NewVirtualFile { @Override public VirtualDirectoryImpl getParent() { - VirtualDirectoryImpl changedParent = VfsData.getChangedParent(this); + VirtualDirectoryImpl changedParent = VfsData.getChangedParent(myId); return changedParent != null ? changedParent : myParent; } @@ -329,7 +329,7 @@ public abstract class VirtualFileSystemEntry extends NewVirtualFile { parent.removeChild(this); VirtualDirectoryImpl directory = (VirtualDirectoryImpl)newParent; - VfsData.changeParent(this, directory); + VfsData.changeParent(myId, directory); directory.addChild(this); updateLinkStatus(); } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilTest.java index 2fcbcc256c82..7f747f90ff07 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/VfsUtilTest.java @@ -417,6 +417,52 @@ public class VfsUtilTest extends PlatformLangTestCase { } + public void testGetParentPerformance() throws IOException { + File tempDir = createTempDirectory(); + final VirtualFile vDir = refreshAndFindFile(tempDir); + assertNotNull(vDir); + assertTrue(vDir.isDirectory()); + final int depth = 10; + new WriteCommandAction.Simple(getProject()) { + @Override + protected void run() throws Throwable { + VirtualFile dir = vDir; + for (int i=0; i