From 98cce32e72c73115d8231fed7939a9969a321afe Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Fri, 4 Sep 2009 22:51:11 +0400 Subject: [PATCH] multithreaded per-index indexing (initial version, false by default) --- .../util/indexing/FileBasedIndex.java | 39 +++++++++++++------ .../src/misc/registry.properties | 4 ++ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java index 98e5bcb4e175..c47de2685dd7 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java @@ -1,6 +1,8 @@ package com.intellij.util.indexing; import com.intellij.AppTopics; +import com.intellij.concurrency.Job; +import com.intellij.concurrency.JobScheduler; import com.intellij.ide.startup.CacheUpdater; import com.intellij.ide.startup.impl.FileSystemSynchronizerImpl; import com.intellij.lang.ASTNode; @@ -26,6 +28,7 @@ import com.intellij.openapi.util.Key; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.ShutDownTracker; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.vfs.*; import com.intellij.openapi.vfs.ex.VirtualFileManagerEx; import com.intellij.openapi.vfs.newvfs.ManagingFS; @@ -102,6 +105,7 @@ public class FileBasedIndex implements ApplicationComponent { private final Map myTransactionMap = new HashMap(); private static final int ALREADY_PROCESSED = 0x02; + private static final String USE_MULTITHREADED_INDEXING = "fileIndex.multithreaded"; public void requestReindex(final VirtualFile file) { myChangedFilesUpdater.invalidateIndices(file, true); @@ -1063,8 +1067,8 @@ public class FileBasedIndex implements ApplicationComponent { FileContent fc = null; PsiFile psiFile = null; - //final Job job = JobScheduler.getInstance().createJob("IndexJob", Job.DEFAULT_PRIORITY / 2); + final List tasks = new ArrayList(); for (final ID indexId : myIndices.keySet()) { if (shouldIndexFile(file, indexId)) { if (fc == null) { @@ -1090,8 +1094,8 @@ public class FileBasedIndex implements ApplicationComponent { } final FileContent _fc = fc; - //job.addTask(new Runnable() { - // public void run() { + tasks.add(new Runnable() { + public void run() { try { updateSingleIndex(indexId, file, _fc); } @@ -1099,17 +1103,30 @@ public class FileBasedIndex implements ApplicationComponent { requestRebuild(indexId); LOG.info(e); } - //} - //}); + } + }); } } - //try { - // job.scheduleAndWaitForResults(); - //} - //catch (Throwable throwable) { - // LOG.info(throwable); - //} + if (tasks.size() > 0) { + if (Registry.get(USE_MULTITHREADED_INDEXING).asBoolean()) { + final Job job = JobScheduler.getInstance().createJob("IndexJob", Job.DEFAULT_PRIORITY / 2); + try { + for (Runnable task : tasks) { + job.addTask(task); + } + job.scheduleAndWaitForResults(); + } + catch (Throwable throwable) { + LOG.info(throwable); + } + } + else { + for (Runnable task : tasks) { + task.run(); + } + } + } if (psiFile != null) { psiFile.putUserData(PsiFileImpl.BUILDING_STUB, null); diff --git a/platform/platform-resources-en/src/misc/registry.properties b/platform/platform-resources-en/src/misc/registry.properties index 871f138496af..4e4aeb6dfd0e 100644 --- a/platform/platform-resources-en/src/misc/registry.properties +++ b/platform/platform-resources-en/src/misc/registry.properties @@ -2,6 +2,10 @@ fileIndex.background=false fileIndex.background.description=Build/update file indices in background fileIndex.background.restartRequired=true +fileIndex.multithreaded=false +fileIndex.multithreaded.description=When indexing a file start indexers in parallel threads +fileIndex.multithreaded.restartRequired=false + actionSystem.fixLostTyping=true actionSystem.fixLostTyping.description=Redispatch events, lost between actions and dialog show/close actionSystem.fixStickyFocusedWindows=true