I have one real nuisance of an intermittent long read action attributable to the following stack trace (with unnecessary frames removed to keep it semi-compact):
Long read action in com.illuminatedcloud.intellij.lwc.typescript.env.AuraEnabledApexTypeDefinitionsEnvironmentUpdater.lambda$getMetadataFiles$1
======= Stack Trace: =========
"pool-5-thread-3" prio=0 tid=0x0 nid=0x0 waiting on condition
java.lang.Thread.State: TIMED_WAITING
at java.base@21.0.9/jdk.internal.misc.Unsafe.park(Native Method)
at java.base@21.0.9/java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:410)
at com.intellij.openapi.progress.impl.CoreProgressManager.sleepIfNeededToGivePriorityToAnotherThread(CoreProgressManager.java:953)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.runCheckCanceledHooks(ProgressManagerImpl.java:291)
at com.intellij.openapi.progress.impl.CoreProgressManager.doCheckCanceled(CoreProgressManager.java:192)
at com.intellij.openapi.progress.ProgressManager.checkCanceled(ProgressManager.java:336)
at com.intellij.openapi.progress.ProgressIndicatorProvider.checkCanceled(ProgressIndicatorProvider.java:41)
at com.intellij.psi.PsiElementVisitor.visitElement(PsiElementVisitor.java:43)
at com.intellij.lang.javascript.psi.JSRecursiveWalkingElementVisitor.visitElement(JSRecursiveWalkingElementVisitor.java:23)
at com.intellij.lang.javascript.psi.impl.JSFileBaseImpl$1.visitElement(JSFileBaseImpl.java:78)
...
at com.intellij.lang.javascript.stubs.factories.TypeScriptInterfaceStubFactory.createStub(TypeScriptInterfaceStubFactory.kt:10)
at com.intellij.psi.stubs.DefaultStubBuilder$StubBuildingWalkingVisitor.createStub(DefaultStubBuilder.java:87)
at com.intellij.lang.javascript.psi.stubs.impl.JSFileStubBuilder$JSStubBuildingWalkingVisitor.createStub(JSFileStubBuilder.java:133)
at com.intellij.psi.stubs.DefaultStubBuilder$StubBuildingWalkingVisitor.visitNode(DefaultStubBuilder.java:58)
at com.intellij.lang.javascript.psi.stubs.impl.JSFileStubBuilder$1.visitNode(JSFileStubBuilder.java:89)
at com.intellij.psi.stubs.DefaultStubBuilder$StubBuildingWalkingVisitor.buildStubTree(DefaultStubBuilder.java:53)
at com.intellij.lang.javascript.psi.stubs.impl.JSFileStubBuilder$JSStubBuildingWalkingVisitor.buildStubTreeAndUpdateLinks(JSFileStubBuilder.java:127)
at com.intellij.lang.javascript.psi.stubs.impl.JSFileStubBuilder.doBuildStubTree(JSFileStubBuilder.java:104)
at com.intellij.lang.javascript.psi.stubs.impl.JSFileStubBuilder.buildStubTree(JSFileStubBuilder.java:44)
at com.intellij.psi.stubs.StubTreeBuilder.lambda$buildStubTree$1(StubTreeBuilder.java:145)
...
at com.intellij.psi.stubs.StubUpdatingIndex$2.computeValue(StubUpdatingIndex.java:156)
at com.intellij.util.indexing.SingleEntryIndexer.map(SingleEntryIndexer.java:29)
at com.intellij.util.indexing.SingleEntryIndexer.map(SingleEntryIndexer.java:19)
at com.intellij.util.indexing.impl.MapReduceIndex.mapByIndexer(MapReduceIndex.java:363)
at com.intellij.util.indexing.impl.MapReduceIndex.mapInput(MapReduceIndex.java:354)
at com.intellij.util.indexing.impl.MapReduceIndex.mapInputAndPrepareUpdate(MapReduceIndex.java:279)
at com.intellij.psi.stubs.StubUpdatingIndexStorage.mapInputAndPrepareUpdate(StubUpdatingIndexStorage.java:62)
at com.intellij.psi.stubs.StubUpdatingIndexStorage.mapInputAndPrepareUpdate(StubUpdatingIndexStorage.java:21)
at com.intellij.indexing.composite.CompositeInvertedIndexBase.updateBaseIndex(CompositeInvertedIndexBase.java:278)
at com.intellij.indexing.composite.CompositeInvertedIndexBase.mapInputAndPrepareUpdate(CompositeInvertedIndexBase.java:59)
at com.intellij.indexing.composite.CompositeInvertedIndexBase.mapInputAndPrepareUpdate(CompositeInvertedIndexBase.java:25)
at com.intellij.util.indexing.FileBasedIndexImpl.createSingleIndexValueApplier(FileBasedIndexImpl.java:1674)
at com.intellij.util.indexing.FileBasedIndexImpl.lambda$doIndexFileContent$21(FileBasedIndexImpl.java:1544)
at com.intellij.util.indexing.FileBasedIndexImpl$$Lambda/0x0000000802165e20.run(Unknown Source)
at com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl.lambda$freezeFileTypeTemporarilyWithProvidedValueIn$15(FileTypeManagerImpl.java:775)
at com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl$$Lambda/0x0000000801e97bb0.run(Unknown Source)
at com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl.cacheFileTypesInside(FileTypeManagerImpl.java:846)
at com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl.freezeFileTypeTemporarilyWithProvidedValueIn(FileTypeManagerImpl.java:771)
at com.intellij.util.indexing.FileBasedIndexImpl.doIndexFileContent(FileBasedIndexImpl.java:1497)
at com.intellij.util.indexing.FileBasedIndexImpl.indexFileContent(FileBasedIndexImpl.java:1472)
at com.intellij.util.indexing.FileBasedIndexImpl.processRefreshedFile(FileBasedIndexImpl.java:1412)
at com.intellij.util.indexing.FileBasedIndexImpl$VirtualFileUpdateTask.doProcess(FileBasedIndexImpl.java:1798)
at com.intellij.util.indexing.FileBasedIndexImpl$VirtualFileUpdateTask.doProcess(FileBasedIndexImpl.java:1792)
at com.intellij.util.indexing.UpdateTask.process(UpdateTask.java:65)
at com.intellij.util.indexing.UpdateTask.processAll(UpdateTask.java:34)
at com.intellij.util.indexing.FileBasedIndexImpl.forceUpdate(FileBasedIndexImpl.java:1818)
at com.intellij.util.indexing.FileBasedIndexImpl.ensureUpToDate(FileBasedIndexImpl.java:878)
at com.intellij.util.indexing.FileBasedIndexEx.processAllKeys(FileBasedIndexEx.java:181)
at com.intellij.util.indexing.FileBasedIndexImpl.processAllKeys(FileBasedIndexImpl.java:906)
at com.intellij.util.indexing.FileBasedIndexEx.processAllKeys(FileBasedIndexEx.java:167)
at com.intellij.util.indexing.FileBasedIndexEx.getAllKeys(FileBasedIndexEx.java:161)
at com.illuminatedcloud.intellij.apex.index.AbstractApexDeclarationNameIndex.getAllNames(AbstractApexDeclarationNameIndex.java:160)
at com.illuminatedcloud.intellij.lwc.typescript.env.AuraEnabledApexTypeDefinitionsEnvironmentUpdater.lambda$getMetadataFiles$1(AuraEnabledApexTypeDefinitionsEnvironmentUpdater.java:146)
at com.illuminatedcloud.intellij.lwc.typescript.env.AuraEnabledApexTypeDefinitionsEnvironmentUpdater$$Lambda/0x000000080295ef40.compute(Unknown Source)
at com.intellij.openapi.application.impl.AppImplKt$rethrowCheckedExceptions$2.invoke(appImpl.kt:126)
at com.intellij.platform.locking.impl.NestedLocksThreadingSupport.runReadAction(NestedLocksThreadingSupport.kt:856)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:1069)
at com.intellij.openapi.application.ReadAction.compute(ReadAction.java:66)
at com.illuminatedcloud.intellij.lwc.typescript.env.AuraEnabledApexTypeDefinitionsEnvironmentUpdater.getMetadataFiles(AuraEnabledApexTypeDefinitionsEnvironmentUpdater.java:146)
I have this logic running on a background/worker thread, and it checks quite diligently for indexing/scanning, aborting and rescheduling the work if that’s the case. Nonetheless, the IDE intermittently reports that my plugin may be causing the IDE to run slowly with the thread dump pointing at the stack trace above as the culprit.
As you can see from the stack trace, it’s synchronously building indexes that I never need for this purpose, e.g., the JavaScript stub index.
Note that I’ve tried various ways of enumerating index keys including processAllKeys() instead of getAllKeys() (even though the latter calls the former), but the result is the same.
Is there any way that I can perhaps determine proactively whether or not querying my own index will result in a forced index rebuild like this, or is there something else I should be doing here when enumerating keys from this index that won’t result in this same potential long read action while doing so? I’ve found FileBasedIndexEx.diableUpToDateCheckIn(), but it’s marked as @ApiStatus.Internal so I’m obviously not planning to use it.
I feel like I’m doing (or at least trying to do) everything right here, but I’m still running into the much-feared “Long read action due to ”.
Thanks in advance for any insights/suggestions.