From 19aedae12fa418cc0eeca9a88abd6b3b5a8bdadd Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Sat, 19 Oct 2013 20:30:48 +0200 Subject: [PATCH] better spreading nameIds / caching strings using integer hash from http://burtleburtle.net/bob/hash/integer.html with previous nameId % 16 striping sampling was like 7542400, 16103753, 1844054, 5237640, 6218814, 11005156, 3395732, 8183208, 1897660, 3119959, 2961691, 7768377, 2177568, 3889462, 6146853, 2765254, with new one 8207442, 6253680, 14184952, 4657166, 5186040, 25115754, 10426752, 15750418, 11239308, 5293340, 16883296, 16750920, 6545096, 23295592, 5969384, 4756022, --- .../openapi/vfs/newvfs/impl/FileNameCache.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 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 1afa309b3a94..a13998cf67bc 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 @@ -57,12 +57,24 @@ public class FileNameCache { Object rawName = convertToBytesIfAsciiString(name); IntObjectLinkedMap.MapEntry entry = new IntObjectLinkedMap.MapEntry(id, rawName); - final int stripe = id % ourNameCache.length; + final int stripe = calcStripeIdFromNameId(id); synchronized (ourNameCache[stripe]) { return ourNameCache[stripe].cacheEntry(entry); } } + private static int calcStripeIdFromNameId(int id) { + int h = id; + h -= (h<<6); + h ^= (h>>17); + h -= (h<<9); + h ^= (h<<4); + h -= (h<<3); + h ^= (h<<10); + h ^= (h>>15); + return h % ourNameCache.length; + } + private static Object convertToBytesIfAsciiString(@NotNull String name) { int length = name.length(); if (length == 0) return EMPTY; @@ -80,7 +92,7 @@ public class FileNameCache { @NotNull private static IntObjectLinkedMap.MapEntry getEntry(int id) { - final int stripe = id % ourNameCache.length; + final int stripe = calcStripeIdFromNameId(id); synchronized (ourNameCache[stripe]) { IntObjectLinkedMap.MapEntry entry = ourNameCache[stripe].getCachedEntry(id); if (entry != null) {