From f68b92de592b1c78a93239dd08bfa176334d1981 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Mon, 14 Mar 2016 14:58:20 +0300 Subject: [PATCH] reduce number of spawned threads: use one thread to load all tool windows instead of 13 threads --- .../wm/impl/ToolWindowManagerImpl.java | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java index b2f3f4598d4a..02c48d2ca1cf 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowManagerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -483,37 +483,39 @@ public final class ToolWindowManagerImpl extends ToolWindowManagerEx implements } private void registerToolWindowsFromBeans() { - ToolWindowEP[] beans = Extensions.getExtensions(ToolWindowEP.EP_NAME); - for (final ToolWindowEP bean : beans) { - final Condition condition = bean.getCondition(); - if (condition == null) { - initToolWindow(bean); - } - else { - checkConditionInReadAction(bean, condition); - } - } + List beans = new ArrayList<>(Arrays.asList(Extensions.getExtensions(ToolWindowEP.EP_NAME))); + Collections.reverse(beans); + + checkConditionsInReadAction(beans, new ArrayList<>()); } - private void checkConditionInReadAction(@NotNull final ToolWindowEP bean, @NotNull final Condition condition) { + private void checkConditionsInReadAction(@NotNull List beans, @NotNull List checkedSuccessfully) { ProgressIndicatorUtils.scheduleWithWriteActionPriority(new ReadTask() { - @Nullable @Override public Continuation performInReadAction(@NotNull ProgressIndicator indicator) throws ProcessCanceledException { - if (!myProject.isDisposed() && condition.value(myProject)) { - return new Continuation(() -> { - if (!myProject.isDisposed() && getToolWindow(bean.id) == null) { - initToolWindow(bean); - } - }, ModalityState.any()); + for (int i = beans.size() - 1; i >= 0; i--) { + indicator.checkCanceled(); + ToolWindowEP bean = beans.remove(i); + Condition condition = ObjectUtils.notNull(bean.getCondition(), Conditions.alwaysTrue()); + if (!myProject.isDisposed() && condition.value(myProject)) { + checkedSuccessfully.add(bean); + } } - return null; + return new Continuation(() -> { + if (!myProject.isDisposed()) { + for (ToolWindowEP bean : checkedSuccessfully) { + if (getToolWindow(bean.id) == null) { + initToolWindow(bean); + } + } + } + }, ModalityState.any()); } @Override public void onCanceled(@NotNull ProgressIndicator indicator) { - checkConditionInReadAction(bean, condition); + checkConditionsInReadAction(beans, checkedSuccessfully); } }); }