review feedback

This commit is contained in:
Maxim.Mossienko
2016-11-14 12:43:16 +01:00
parent 82284d4761
commit 4e218579d7
3 changed files with 35 additions and 44 deletions
@@ -32,6 +32,8 @@ import com.intellij.openapi.util.Ref
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.text.StringUtil
import com.intellij.openapi.vfs.*
import com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent
import com.intellij.openapi.vfs.newvfs.events.VFileDeleteEvent
import com.intellij.openapi.vfs.newvfs.events.VFileEvent
import com.intellij.openapi.vfs.newvfs.events.VFilePropertyChangeEvent
import com.intellij.openapi.vfs.newvfs.impl.VirtualFileSystemEntry
@@ -64,6 +66,7 @@ import com.intellij.util.FileContentUtil
import com.intellij.util.Processor
import com.intellij.util.indexing.*
import com.intellij.util.io.*
import groovy.transform.CompileStatic
import org.jetbrains.annotations.NotNull
/**
* @author Eugene Zhuravlev
@@ -566,14 +569,14 @@ class IndexTest extends JavaCodeInsightFixtureTestCase {
VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor() {
@Override
boolean visitFile(@NotNull VirtualFile visitedFile) {
iterator.processFile(visitedFile);
return true;
iterator.processFile(visitedFile)
return true
}
});
})
}
protected void doInvalidateIndicesForFile(VirtualFile file, boolean contentChange) {
vfsEventMerger.recordBeforeFileEvent(((VirtualFileWithId)file).id, file, contentChange);
vfsEventMerger.recordBeforeFileEvent(((VirtualFileWithId)file).id, file, contentChange)
}
@Override
@@ -586,12 +589,12 @@ class IndexTest extends JavaCodeInsightFixtureTestCase {
vfsEventMerger.processChanges(new VfsEventsMerger.VfsEventProcessor() {
@Override
boolean process(VfsEventsMerger.ChangeInfo info) {
operation.set(info.toString());
operation.set(info.toString())
return true
}
})
StringUtil.replace(operation.get(), file.getPath(), file.getName());
StringUtil.replace(operation.get(), file.getPath(), file.getName())
}
}
@@ -601,7 +604,7 @@ class IndexTest extends JavaCodeInsightFixtureTestCase {
ApplicationManager.getApplication().getMessageBus().connect(getTestRootDisposable()).subscribe(
VirtualFileManager.VFS_CHANGES,
listener
);
)
def fileName = "test.txt"
final VirtualFile testFile = myFixture.addFileToProject(fileName, "test").getVirtualFile()
@@ -614,17 +617,17 @@ class IndexTest extends JavaCodeInsightFixtureTestCase {
assertEquals("file: $fileName\n" +
"operation: REMOVE ADD", listener.indexingOperation(testFile))
VfsUtil.saveText(testFile, "foo");
VfsUtil.saveText(testFile, "bar");
VfsUtil.saveText(testFile, "foo")
VfsUtil.saveText(testFile, "bar")
assertEquals("file: $fileName\n" +
"operation: UPDATE-REMOVE UPDATE", listener.indexingOperation(testFile));
"operation: UPDATE-REMOVE UPDATE", listener.indexingOperation(testFile))
VfsUtil.saveText(testFile, "baz")
testFile.delete(null)
assertEquals("file: $fileName\n" +
"operation: REMOVE", listener.indexingOperation(testFile));
"operation: REMOVE", listener.indexingOperation(testFile))
}
void "test files inside copied directory are indexed"() {
@@ -643,35 +646,35 @@ class IndexTest extends JavaCodeInsightFixtureTestCase {
assert JavaFileElementType.isInSourceContent(myFixture.tempDirFixture.getFile('another/doo/A.java'))
}
@CompileStatic
void "test Vfs Events Processing Performance"() {
def filename = 'A.java'
myFixture.addFileToProject('foo/bar/' + filename, 'class A {}')
PlatformTestUtil.startPerformanceTest("Vfs Event Processing By Index", 1000, {
def files = FilenameIndex.getFilesByName(project, filename, GlobalSearchScope.moduleScope(myModule))
assert files != null
assert files.length == 1
assert files?.length == 1
VirtualFile file = files[0].virtualFile
def filename2 = 'B.java'
def max = 100000
List<VFileEvent> eventList = new ArrayList<>(max);
def len = max / 2;
List<VFileEvent> eventList = new ArrayList<>(max)
def len = max / 2
for(int i = 0; i < len; ++i) {
eventList.add(new VFilePropertyChangeEvent(null, file, VirtualFile.PROP_NAME, filename, filename2, true)) ;
eventList.add(new VFilePropertyChangeEvent(null, file, VirtualFile.PROP_NAME, filename2, filename, true)) ;
eventList.add(new VFilePropertyChangeEvent(null, file, VirtualFile.PROP_NAME, filename, filename2, true))
eventList.add(new VFilePropertyChangeEvent(null, file, VirtualFile.PROP_NAME, filename2, filename, true))
eventList.add(new VFileDeleteEvent(null, file, true))
eventList.add(new VFileCreateEvent(null, file.parent, filename, false, true))
}
IndexedFilesListener indexedFilesListener = ((FileBasedIndexImpl)FileBasedIndex.instance).changedFilesCollector
indexedFilesListener.before(eventList);
indexedFilesListener.after(eventList);
indexedFilesListener.before(eventList)
indexedFilesListener.after(eventList)
files = FilenameIndex.getFilesByName(project, filename, GlobalSearchScope.moduleScope(myModule))
assert files != null
assert files.length == 1
}).cpuBound().ioBound().assertTiming();
assert files?.length == 1
}).cpuBound().ioBound().assertTiming()
}
}
@@ -39,7 +39,6 @@ import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.impl.BackgroundableProcessIndicator;
import com.intellij.openapi.progress.util.ProgressIndicatorUtils;
import com.intellij.openapi.project.*;
import com.intellij.openapi.roots.*;
import com.intellij.openapi.roots.impl.PushedFilePropertiesUpdaterImpl;
@@ -2003,11 +2002,7 @@ public class FileBasedIndexImpl extends FileBasedIndex {
private void processFilesInReadActionWithYieldingToWriteAction() {
try {
while (myVfsEventsMerger.hasChanges()) {
boolean result = ProgressIndicatorUtils
.runInReadActionWithWriteActionPriority(this::processFilesInReadAction, null);
if (!result) {
ProgressIndicatorUtils.yieldToPendingWriteActions();
}
ProgressManager.getInstance().runInReadActionWithWriteActionPriority(this::processFilesInReadAction);
}
}
finally {
@@ -23,7 +23,7 @@ import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.Nullable;
/**
* Created by Maxim.Mossienko on 11/10/2016.
* @author Maxim.Mossienko on 11/10/2016.
*/
public class VfsEventsMerger {
public void recordFileEvent(int fileId, VirtualFile file, boolean contentChange) {
@@ -35,19 +35,12 @@ public class VfsEventsMerger {
}
private void updateChange(int fileId, VirtualFile file, short mask) {
ChangeInfo newChangeInfo = new ChangeInfo(file, mask, null);
ChangeInfo existingChangeInfo = myChangeInfos.cacheOrGet(fileId, newChangeInfo);
if (existingChangeInfo != newChangeInfo) {
while (true) {
newChangeInfo = new ChangeInfo(file, mask, existingChangeInfo);
if (existingChangeInfo == null) {
existingChangeInfo = myChangeInfos.cacheOrGet(fileId, newChangeInfo);
} else {
if (myChangeInfos.replace(fileId, existingChangeInfo, newChangeInfo)) break;
existingChangeInfo = myChangeInfos.get(fileId);
}
}
while (true) {
ChangeInfo existingChangeInfo = myChangeInfos.get(fileId);
ChangeInfo newChangeInfo = new ChangeInfo(file, mask, existingChangeInfo);
boolean replaced = existingChangeInfo == null ? myChangeInfos.putIfAbsent(fileId, newChangeInfo) == null
: myChangeInfos.replace(fileId, existingChangeInfo, newChangeInfo);
if (replaced) break;
}
}
@@ -59,6 +52,7 @@ public class VfsEventsMerger {
// 2. Method processes snapshot of available events at the time of the invokation, it does mean that if events are produced concurrently
// with the processing then set of events will be not empty
// 3. Method regularly checks for cancellations (thus can finish with PCEs) but event processor should process the change info atomically
// (without PCE)
public boolean processChanges(VfsEventProcessor eventProcessor) {
if (!myChangeInfos.isEmpty()) {
int[] fileIds = myChangeInfos.keys(); // snapshot of the keys
@@ -148,5 +142,4 @@ public class VfsEventsMerger {
return fileId;
}
}
}