From 7f800b0fb6770fedbd5ab467531544fe2589ce79 Mon Sep 17 00:00:00 2001 From: Konstantin Nisht Date: Fri, 2 Jan 2026 12:18:14 +0100 Subject: [PATCH] Revert "[threading] IJPL-211526: Remove `Dispatchers.UiWithModelAccess` during UI initialization" This commit leads to degradation in RUST-19396 and IJPL-225525 This reverts commit 3e00bf95814704db977ca58769f13f0f222455d1. GitOrigin-RevId: 52f0f61d3b37af9bed9aecddad969cb753a94775 --- .../com/intellij/ui/mac/MacOSApplicationProvider.kt | 2 +- .../intellij/ide/ApplicationActivationStateManager.kt | 4 ++-- .../intellij/ide/lightEdit/LightEditFrameWrapper.kt | 4 ++-- .../com/intellij/ide/ui/laf/SystemDarkThemeDetector.kt | 9 +++------ .../openapi/project/impl/IdeProjectFrameAllocator.kt | 4 ++-- .../openapi/wm/impl/ProjectFrameCustomHeaderHelper.kt | 2 +- .../com/intellij/openapi/wm/impl/ProjectFrameHelper.kt | 6 +++--- .../intellij/openapi/wm/impl/ToolWindowManagerImpl.kt | 2 +- .../openapi/wm/impl/headertoolbar/MainToolbar.kt | 3 ++- .../openapi/wm/impl/status/IdeStatusBarImpl.kt | 10 +++++----- .../src/com/intellij/ui/mac/MacDockDelegate.kt | 8 ++++---- 11 files changed, 26 insertions(+), 28 deletions(-) diff --git a/platform/platform-impl/bootstrap/src/com/intellij/ui/mac/MacOSApplicationProvider.kt b/platform/platform-impl/bootstrap/src/com/intellij/ui/mac/MacOSApplicationProvider.kt index 16365aeb86cf..9bd1f54f806f 100644 --- a/platform/platform-impl/bootstrap/src/com/intellij/ui/mac/MacOSApplicationProvider.kt +++ b/platform/platform-impl/bootstrap/src/com/intellij/ui/mac/MacOSApplicationProvider.kt @@ -62,7 +62,7 @@ fun initMacApplication(mainScope: CoroutineScope) { val desktop = Desktop.getDesktop() desktop.setAboutHandler { submit("About", mainScope) { ideFocusManager -> - val project = withContext(Dispatchers.EDT) { + val project = withContext(Dispatchers.UiWithModelAccess) { val project = (ideFocusManager.lastFocusedIdeWindow as? IdeFrame)?.project AboutAction.perform(project) project diff --git a/platform/platform-impl/src/com/intellij/ide/ApplicationActivationStateManager.kt b/platform/platform-impl/src/com/intellij/ide/ApplicationActivationStateManager.kt index c163f8af76ca..2b6feedc5f65 100644 --- a/platform/platform-impl/src/com/intellij/ide/ApplicationActivationStateManager.kt +++ b/platform/platform-impl/src/com/intellij/ide/ApplicationActivationStateManager.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.ide import com.intellij.openapi.application.* @@ -68,7 +68,7 @@ object ApplicationActivationStateManager { if (ideFrame != null) { // getIdeFrameFromWindow returns something from a UI tree, so, if not null, it must be Window val publisher = app.getMessageBus().syncPublisher(ApplicationActivationListener.TOPIC) - withContext(Dispatchers.EDT) { + withContext(Dispatchers.UiWithModelAccess) { publisher.delayedApplicationDeactivated(ideFrame as Window) } } diff --git a/platform/platform-impl/src/com/intellij/ide/lightEdit/LightEditFrameWrapper.kt b/platform/platform-impl/src/com/intellij/ide/lightEdit/LightEditFrameWrapper.kt index bb985b7b79fd..ccf410971cfa 100644 --- a/platform/platform-impl/src/com/intellij/ide/lightEdit/LightEditFrameWrapper.kt +++ b/platform/platform-impl/src/com/intellij/ide/lightEdit/LightEditFrameWrapper.kt @@ -8,7 +8,7 @@ import com.intellij.ide.lightEdit.project.LightEditFileEditorManagerImpl import com.intellij.ide.lightEdit.statusBar.* import com.intellij.openapi.Disposable import com.intellij.openapi.application.ApplicationManager -import com.intellij.openapi.application.EDT +import com.intellij.openapi.application.UiWithModelAccess import com.intellij.openapi.components.ComponentManagerEx import com.intellij.openapi.components.serviceAsync import com.intellij.openapi.extensions.LoadingOrder @@ -45,7 +45,7 @@ import javax.swing.JFrame @RequiresEdt internal fun allocateLightEditFrame(project: Project, frameInfo: FrameInfo?): LightEditFrameWrapper { return runWithModalProgressBlocking(ModalTaskOwner.guess(), "") { - withContext(Dispatchers.EDT) { + withContext(Dispatchers.UiWithModelAccess) { val wrapper = allocateLightEditFrame(project) { frame -> LightEditFrameWrapper(project = project, frame = frame ?: createIdeFrame(frameInfo ?: FrameInfo())) } as LightEditFrameWrapper diff --git a/platform/platform-impl/src/com/intellij/ide/ui/laf/SystemDarkThemeDetector.kt b/platform/platform-impl/src/com/intellij/ide/ui/laf/SystemDarkThemeDetector.kt index 207fca3ce6b2..50b216880959 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/laf/SystemDarkThemeDetector.kt +++ b/platform/platform-impl/src/com/intellij/ide/ui/laf/SystemDarkThemeDetector.kt @@ -1,11 +1,8 @@ -// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.ide.ui.laf import com.intellij.jna.JnaLoader -import com.intellij.openapi.application.ApplicationManager -import com.intellij.openapi.application.EDT -import com.intellij.openapi.application.ModalityState -import com.intellij.openapi.application.asContextElement +import com.intellij.openapi.application.* import com.intellij.openapi.components.service import com.intellij.openapi.util.SystemInfo import com.intellij.openapi.util.SystemInfoRt @@ -58,7 +55,7 @@ private abstract class AsyncDetector : SystemDarkThemeDetector() { override fun check(parameter: Boolean?) { service().coroutineScope.launch { val isDark = isDark() - withContext(Dispatchers.EDT + ModalityState.any().asContextElement()) { + withContext(Dispatchers.UiWithModelAccess + ModalityState.any().asContextElement()) { syncFunction.accept(isDark, parameter) } } diff --git a/platform/platform-impl/src/com/intellij/openapi/project/impl/IdeProjectFrameAllocator.kt b/platform/platform-impl/src/com/intellij/openapi/project/impl/IdeProjectFrameAllocator.kt index f32543977c1a..90142dc15f28 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/impl/IdeProjectFrameAllocator.kt +++ b/platform/platform-impl/src/com/intellij/openapi/project/impl/IdeProjectFrameAllocator.kt @@ -123,7 +123,7 @@ internal class IdeProjectFrameAllocator( launch { val fileEditorManager = project.serviceAsync() as FileEditorManagerImpl fileEditorManager.initJob.join() - withContext(Dispatchers.EDT) { + withContext(Dispatchers.UiWithModelAccess) { frameHelper.toolWindowPane.setDocumentComponent(fileEditorManager.mainSplitters) } } @@ -222,7 +222,7 @@ internal class IdeProjectFrameAllocator( else { val frameHelper = IdeProjectFrameHelper(createIdeFrame(frameInfo), loadingState = loadingState) // must be after preInit (frame decorator is required to set a full-screen mode) - withContext(Dispatchers.EDT) { + withContext(Dispatchers.UiWithModelAccess) { frameHelper.frame.isVisible = true } completeFrameAndCloseOnCancel(frameHelper) { diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ProjectFrameCustomHeaderHelper.kt b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ProjectFrameCustomHeaderHelper.kt index 8e86187fb980..3129c19aa229 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ProjectFrameCustomHeaderHelper.kt +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ProjectFrameCustomHeaderHelper.kt @@ -307,7 +307,7 @@ private class ToolbarCreator( private fun startNewJob(): Deferred { val newJob = cs.async( - Dispatchers.EDT + + Dispatchers.UiWithModelAccess + ModalityState.any().asContextElement() + CoroutineName("Lazy MainToolbar computation") ) { diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ProjectFrameHelper.kt b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ProjectFrameHelper.kt index 55e90272d4c8..5b31b8d7be68 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ProjectFrameHelper.kt +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ProjectFrameHelper.kt @@ -18,8 +18,8 @@ import com.intellij.openapi.actionSystem.UiDataProvider import com.intellij.openapi.actionSystem.impl.MouseGestureManager import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.ApplicationNamesInfo -import com.intellij.openapi.application.EDT import com.intellij.openapi.application.ModalityState +import com.intellij.openapi.application.UiWithModelAccess import com.intellij.openapi.application.impl.InternalUICustomization import com.intellij.openapi.application.impl.LaterInvocator import com.intellij.openapi.components.service @@ -349,7 +349,7 @@ abstract class ProjectFrameHelper internal constructor( suspend fun updateTitle(title: String, project: Project) { val titleInfoProviders = getTitleInfoProviders() - withContext(Dispatchers.EDT) { + withContext(Dispatchers.UiWithModelAccess) { this@ProjectFrameHelper.title = title updateTitle(project = project, titleInfoProviders = titleInfoProviders) } @@ -435,7 +435,7 @@ abstract class ProjectFrameHelper internal constructor( this.project = project - withContext(Dispatchers.EDT) { + withContext(Dispatchers.UiWithModelAccess) { applyInitBounds() if (statusBar == null) { diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.kt b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.kt index a8f61bb5542a..4afa5fc580c5 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.kt +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.kt @@ -1621,7 +1621,7 @@ open class ToolWindowManagerImpl @NonInjectable @TestOnly internal constructor( override fun invokeLater(runnable: Runnable) { if (!toolWindowSetInitializer.addToPendingTasksIfNotInitialized(runnable)) { - coroutineScope.launch(Dispatchers.EDT + ModalityState.nonModal().asContextElement()) { + coroutineScope.launch(Dispatchers.UiWithModelAccess + ModalityState.nonModal().asContextElement()) { runnable.run() } } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/headertoolbar/MainToolbar.kt b/platform/platform-impl/src/com/intellij/openapi/wm/impl/headertoolbar/MainToolbar.kt index 9b122d822027..24c503e91170 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/headertoolbar/MainToolbar.kt +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/headertoolbar/MainToolbar.kt @@ -26,6 +26,7 @@ import com.intellij.openapi.actionSystem.toolbarLayout.CompressingLayoutStrategy import com.intellij.openapi.actionSystem.toolbarLayout.ToolbarLayoutStrategy import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.EDT +import com.intellij.openapi.application.UiWithModelAccess import com.intellij.openapi.application.impl.BorderPainterHolder import com.intellij.openapi.application.impl.InternalUICustomization import com.intellij.openapi.diagnostic.logger @@ -208,7 +209,7 @@ class MainToolbar( for (widget in widgets) { // separate EDT action - avoid long-running update - withContext(Dispatchers.EDT) { + withContext(Dispatchers.UiWithModelAccess) { widget.first.updateActions() } } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/IdeStatusBarImpl.kt b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/IdeStatusBarImpl.kt index b35ba7731c47..93b494c6992e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/IdeStatusBarImpl.kt +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/status/IdeStatusBarImpl.kt @@ -302,7 +302,7 @@ open class IdeStatusBarImpl @Internal constructor( * @param widget widget to add */ internal suspend fun addWidgetToLeft(widget: StatusBarWidget) { - withContext(Dispatchers.EDT) { + withContext(Dispatchers.UiWithModelAccess) { addWidget(widget, Position.LEFT, LoadingOrder.ANY) } } @@ -330,7 +330,7 @@ open class IdeStatusBarImpl @Internal constructor( // Create components in parallel (performance optimization) val beans: List = span("status bar widget creating") { widgets.map { (widget, anchor) -> - val component = span(widget.ID(), Dispatchers.EDT + anyModality) { + val component = span(widget.ID(), Dispatchers.UiWithModelAccess + anyModality) { val c = wrap(widget) if (c is StatusBarWidgetWrapper) { c.beforeUpdate() @@ -341,7 +341,7 @@ open class IdeStatusBarImpl @Internal constructor( } } - withContext(Dispatchers.EDT + anyModality + CoroutineName("status bar widget adding")) { + withContext(Dispatchers.UiWithModelAccess + anyModality + CoroutineName("status bar widget adding")) { // Add all to self for (bean in beans) { addWidgetToSelf(bean, parentDisposable) @@ -358,14 +358,14 @@ open class IdeStatusBarImpl @Internal constructor( // Fire events if (listeners.hasListeners()) { - withContext(Dispatchers.EDT + anyModality) { + withContext(Dispatchers.UiWithModelAccess + anyModality) { for (bean in beans) { fireWidgetAdded(bean.widget, bean.anchor) } } } - withContext(Dispatchers.EDT) { + withContext(Dispatchers.UiWithModelAccess) { PopupHandler.installPopupMenu(this@IdeStatusBarImpl, StatusBarWidgetsActionGroup.GROUP_ID, ActionPlaces.STATUS_BAR_PLACE) } } diff --git a/platform/platform-impl/src/com/intellij/ui/mac/MacDockDelegate.kt b/platform/platform-impl/src/com/intellij/ui/mac/MacDockDelegate.kt index 0846aeffb0e6..031ba7bfc9c4 100644 --- a/platform/platform-impl/src/com/intellij/ui/mac/MacDockDelegate.kt +++ b/platform/platform-impl/src/com/intellij/ui/mac/MacDockDelegate.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.ui.mac import com.intellij.ide.DataManager @@ -7,7 +7,7 @@ import com.intellij.ide.SystemDock import com.intellij.openapi.actionSystem.ActionPlaces import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.ex.ActionUtil -import com.intellij.openapi.application.EDT +import com.intellij.openapi.application.UiWithModelAccess import com.intellij.openapi.components.serviceAsync import com.intellij.openapi.diagnostic.getOrHandleException import com.intellij.openapi.diagnostic.logger @@ -19,7 +19,7 @@ import java.awt.* internal suspend fun createMacDelegate(): SystemDock? { // todo get rid of UI dispatcher here - return withContext(Dispatchers.EDT) { + return withContext(Dispatchers.UiWithModelAccess) { val dockMenu = PopupMenu("DockMenu") runCatching { @@ -53,7 +53,7 @@ private class MacDockDelegate(private val recentProjectsMenu: Menu) : SystemDock override suspend fun updateRecentProjectsMenu() { val projectListActionProvider = serviceAsync() // todo get rid of UI dispatcher here - withContext(Dispatchers.EDT) { + withContext(Dispatchers.UiWithModelAccess) { recentProjectsMenu.removeAll() for (action in projectListActionProvider.getActionsWithoutGroups()) { if (action !is ProjectToolbarWidgetPresentable) {