From c895fdf4a35eed283574ceee125b67d2d2edea99 Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Mon, 1 Jul 2013 19:35:21 +0200 Subject: [PATCH] simple 16x striping for namescache --- .../vfs/newvfs/impl/FileNameCache.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/FileNameCache.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/FileNameCache.java index 5e6b315a3580..1afa309b3a94 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/FileNameCache.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/FileNameCache.java @@ -33,7 +33,14 @@ import org.jetbrains.annotations.Nullable; public class FileNameCache { private static final PersistentStringEnumerator ourNames = FSRecords.getNames(); @NonNls private static final String EMPTY = ""; - private static final IntSLRUCache> ourNameCache = new IntSLRUCache>(40000, 20000); + @SuppressWarnings("unchecked") private static final IntSLRUCache>[] ourNameCache = new IntSLRUCache[16]; + static { + final int protectedSize = 40000 / ourNameCache.length; + final int probationalSize = 20000 / ourNameCache.length; + for(int i = 0; i < ourNameCache.length; ++i) { + ourNameCache[i] = new IntSLRUCache>(protectedSize, probationalSize); + } + } public static int storeName(@NotNull String name) { final int idx = FSRecords.getNameId(name); @@ -50,8 +57,9 @@ public class FileNameCache { Object rawName = convertToBytesIfAsciiString(name); IntObjectLinkedMap.MapEntry entry = new IntObjectLinkedMap.MapEntry(id, rawName); - synchronized (ourNameCache) { - return ourNameCache.cacheEntry(entry); + final int stripe = id % ourNameCache.length; + synchronized (ourNameCache[stripe]) { + return ourNameCache[stripe].cacheEntry(entry); } } @@ -72,8 +80,9 @@ public class FileNameCache { @NotNull private static IntObjectLinkedMap.MapEntry getEntry(int id) { - synchronized (ourNameCache) { - IntObjectLinkedMap.MapEntry entry = ourNameCache.getCachedEntry(id); + final int stripe = id % ourNameCache.length; + synchronized (ourNameCache[stripe]) { + IntObjectLinkedMap.MapEntry entry = ourNameCache[stripe].getCachedEntry(id); if (entry != null) { return entry; }