Skip to content

Conversation

@pq
Copy link
Collaborator

@pq pq commented May 1, 2025

Speeds up SdkRunConfig.getState which necessarily runs on the Event Dispatch Thread.

The fix has two parts:

  1. Move the expensive call to ModuleUtilCore.findModuleForFile(..) into an async read action (because we can) and
  2. Speed up inProject because we can't background it and there's a speedy alternative to the old more expensive approach

Addresses stack traces like this:

java.lang.Throwable: Slow operations are prohibited on EDT. See SlowOperations.assertSlowOperationsAreAllowed javadoc.
	at com.intellij.openapi.diagnostic.Logger.error(Logger.java:376)
	at com.intellij.util.SlowOperations.assertSlowOperationsAreAllowed(SlowOperations.java:114)
	at com.intellij.workspaceModel.core.fileIndex.impl.WorkspaceFileIndexDataImpl.ensureIsUpToDate(WorkspaceFileIndexDataImpl.kt:153)
	at com.intellij.workspaceModel.core.fileIndex.impl.WorkspaceFileIndexDataImpl.getFileInfo(WorkspaceFileIndexDataImpl.kt:98)
	at com.intellij.workspaceModel.core.fileIndex.impl.WorkspaceFileIndexImpl.getFileInfo(WorkspaceFileIndexImpl.kt:267)
	at com.intellij.workspaceModel.core.fileIndex.impl.WorkspaceFileIndexImpl.findFileSetWithCustomData(WorkspaceFileIndexImpl.kt:250)
	at com.intellij.openapi.roots.impl.ProjectFileIndexImpl.getModuleForFile(ProjectFileIndexImpl.java:102)
	at com.intellij.openapi.roots.impl.ProjectFileIndexImpl.getModuleForFile(ProjectFileIndexImpl.java:95)
	at com.intellij.openapi.module.ModuleUtilCore.lambda$findModuleForFile$0(ModuleUtilCore.java:84)
	at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runReadAction(AnyThreadWriteThreadingSupport.kt:272)
	at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runReadAction(AnyThreadWriteThreadingSupport.kt:262)
	at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:863)
	at com.intellij.openapi.application.ReadAction.compute(ReadAction.java:66)
	at com.intellij.openapi.module.ModuleUtilCore.findModuleForFile(ModuleUtilCore.java:84)
	at io.flutter.run.SdkRunConfig.getState(SdkRunConfig.java:139)
	at io.flutter.run.SdkRunConfig.getState(SdkRunConfig.java:59)

See: #8089


  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

@pq pq requested a review from jwren May 1, 2025 22:15
@pq pq merged commit 546022d into flutter:master May 21, 2025
7 checks passed
@pq pq deleted the perf_SdkRunConfig.getState branch May 21, 2025 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants