Skip to content

Commit 1169f5e

Browse files
authored
[perf] create action presentations lazily (flutter#8187)
Stops eagerly creating action presentations (allocating resources prematurely and possibly unnecessarily) in favor of the preferred registration in plugin metadata that will only get loaded as-needed. From the inspection: > Reports any actions that are registered in the plugin.xml file and instantiate the com.intellij.openapi.actionSystem.Presentation object in their constructors. > Any of the constructors of AnAction with parameters instantiate the Presentation object. However, instantiating the Presentation object in constructor results in allocating resources, which may not be necessary. Instead of creating an instance of Presentation that stores text, description, or icon, it is more efficient to utilize no-argument constructors of AnAction and other base classes and follow the convention for setting the text, description, and icon in plugin.xml. The IDE will load text, description, and icon only when the action is actually displayed in the UI. > The convention for setting the text, description, and icon is as follows: Set the id attribute for the action in the plugin.xml file. Optionally, set the icon attribute if an icon is needed. Our actions: ![image](https://github.com/user-attachments/assets/7eb77ea8-006b-44aa-afcf-e8c3784f52b3) The only risk is in ensuring that the templated menu text is still getting properly filled in, and I confirmed that: ![image](https://github.com/user-attachments/assets/00697fdf-9a32-4204-ac49-a73c32cdf0c2) --- - [x] I’ve reviewed the contributor guide and applied the relevant portions to this PR. <details> <summary>Contribution guidelines:</summary><br> - See our [contributor guide]([https://github.com/dart-lang/sdk/blob/main/CONTRIBUTING.md](https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview) for general expectations for PRs. - Larger or significant changes should be discussed in an issue before creating a PR. - Dart contributions to our repos should follow the [Dart style guide](https://dart.dev/guides/language/effective-dart) and use `dart format`. - Java and Kotlin contributions should strive to follow Java and Kotlin best practices ([discussion](flutter#8098)). </details>
1 parent 0f8ffa6 commit 1169f5e

File tree

7 files changed

+21
-35
lines changed

7 files changed

+21
-35
lines changed

flutter-idea/src/io/flutter/actions/DeviceSelectorRefresherAction.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,15 @@
55
*/
66
package io.flutter.actions;
77

8-
import com.intellij.openapi.actionSystem.*;
8+
import com.intellij.openapi.actionSystem.ActionUpdateThread;
9+
import com.intellij.openapi.actionSystem.AnAction;
10+
import com.intellij.openapi.actionSystem.AnActionEvent;
911
import com.intellij.openapi.project.Project;
10-
import icons.FlutterIcons;
1112
import io.flutter.run.daemon.DeviceService;
1213
import io.flutter.utils.FlutterModuleUtils;
1314
import org.jetbrains.annotations.NotNull;
1415

1516
public class DeviceSelectorRefresherAction extends AnAction {
16-
public DeviceSelectorRefresherAction() {
17-
super(FlutterIcons.RefreshItems);
18-
}
19-
2017
@Override
2118
public void actionPerformed(@NotNull AnActionEvent e) {
2219
final Project project = e.getProject();

flutter-idea/src/io/flutter/actions/RestartFlutterDaemonAction.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
import org.jetbrains.annotations.NotNull;
1414

1515
public class RestartFlutterDaemonAction extends AnAction {
16-
public RestartFlutterDaemonAction() {
17-
super("Refresh");
18-
}
19-
2016
@Override
2117
public void actionPerformed(AnActionEvent event) {
2218
final Project project = event.getProject();

flutter-idea/src/io/flutter/actions/RunFlutterAction.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.jetbrains.annotations.NotNull;
2626
import org.jetbrains.annotations.Nullable;
2727

28-
import javax.swing.*;
2928
import java.util.ArrayList;
3029
import java.util.List;
3130
import java.util.Objects;
@@ -35,14 +34,10 @@ public abstract class RunFlutterAction extends AnAction {
3534
private final @NotNull FlutterLaunchMode myLaunchMode;
3635
private final @NotNull String myExecutorId;
3736

38-
public RunFlutterAction(@NotNull String text,
39-
@NotNull String detailedTextKey,
40-
@NotNull String description,
41-
@NotNull Icon icon,
42-
@NotNull FlutterLaunchMode launchMode,
43-
@NotNull String executorId) {
44-
super(text, description, icon);
45-
37+
public RunFlutterAction(
38+
@NotNull String detailedTextKey,
39+
@NotNull FlutterLaunchMode launchMode,
40+
@NotNull String executorId) {
4641
myDetailedTextKey = detailedTextKey;
4742
myLaunchMode = launchMode;
4843
myExecutorId = executorId;

flutter-idea/src/io/flutter/actions/RunProfileFlutterApp.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@
55
*/
66
package io.flutter.actions;
77

8-
import com.intellij.icons.AllIcons;
98
import com.intellij.openapi.wm.ToolWindowId;
10-
import io.flutter.FlutterBundle;
119
import io.flutter.run.FlutterLaunchMode;
1210

1311
public class RunProfileFlutterApp extends RunFlutterAction {
14-
public static final String TEXT = FlutterBundle.message("app.profile.action.text");
15-
public static final String DESCRIPTION = FlutterBundle.message("app.profile.action.description");
1612
private static final String TEXT_DETAIL_MSG_KEY = "app.profile.config.action.text";
1713

1814
public RunProfileFlutterApp() {
19-
super(TEXT, TEXT_DETAIL_MSG_KEY, DESCRIPTION, AllIcons.Actions.Execute, FlutterLaunchMode.PROFILE, ToolWindowId.RUN);
15+
super(TEXT_DETAIL_MSG_KEY, FlutterLaunchMode.PROFILE, ToolWindowId.RUN);
2016
}
2117
}

flutter-idea/src/io/flutter/actions/RunReleaseFlutterApp.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,13 @@
55
*/
66
package io.flutter.actions;
77

8-
import com.intellij.icons.AllIcons;
98
import com.intellij.openapi.wm.ToolWindowId;
10-
import io.flutter.FlutterBundle;
119
import io.flutter.run.FlutterLaunchMode;
1210

1311
public class RunReleaseFlutterApp extends RunFlutterAction {
14-
public static final String TEXT = FlutterBundle.message("app.release.action.text");
15-
public static final String DESCRIPTION = FlutterBundle.message("app.release.action.description");
1612
private static final String TEXT_DETAIL_MSG_KEY = "app.release.config.action.text";
1713

1814
public RunReleaseFlutterApp() {
19-
super(TEXT, TEXT_DETAIL_MSG_KEY, DESCRIPTION, AllIcons.Actions.Execute, FlutterLaunchMode.RELEASE, ToolWindowId.RUN);
15+
super(TEXT_DETAIL_MSG_KEY, FlutterLaunchMode.RELEASE, ToolWindowId.RUN);
2016
}
2117
}

resources/META-INF/plugin.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@
160160
icon="FlutterIcons.Phone"/>
161161
<action id="Flutter.DeviceSelectorRefresher" class="io.flutter.actions.DeviceSelectorRefresherAction"
162162
text="Refresh Device List"
163-
description="Refresh device list" />
163+
description="Refresh device list"
164+
icon="FlutterIcons.RefreshItems"/>
164165
<add-to-group anchor="before" group-id="RunToolbarMainActionGroup" relative-to-action="RedesignedRunConfigurationSelector"/>
165166
</group>
166167

@@ -316,12 +317,14 @@
316317
<separator/>
317318
<!--suppress PluginXmlCapitalization -->
318319
<action id="Flutter.Menu.RunProfileAction" class="io.flutter.actions.RunProfileFlutterApp"
319-
description="Flutter Run Profile Mode"
320+
description="Run Flutter app in profile mode"
321+
text="Run in Flutter Profile Mode"
320322
icon="AllIcons.Actions.Execute">
321323
</action>
322324
<!--suppress PluginXmlCapitalization -->
323325
<action id="Flutter.Menu.RunReleaseAction" class="io.flutter.actions.RunReleaseFlutterApp"
324-
description="Flutter Run Release Mode"
326+
description="Run Flutter app in release mode"
327+
text="Run in Flutter release mode"
325328
icon="AllIcons.Actions.Execute">
326329
</action>
327330
<reference ref="AttachDebuggerAction"/>

resources/META-INF/plugin_template.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
6262
icon="FlutterIcons.Phone"/>
6363
<action id="Flutter.DeviceSelectorRefresher" class="io.flutter.actions.DeviceSelectorRefresherAction"
6464
text="Refresh Device List"
65-
description="Refresh device list" />
65+
description="Refresh device list"
66+
icon="FlutterIcons.RefreshItems"/>
6667
<add-to-group anchor="before" group-id="RunToolbarMainActionGroup" relative-to-action="RedesignedRunConfigurationSelector"/>
6768
</group>
6869

@@ -218,12 +219,14 @@
218219
<separator/>
219220
<!--suppress PluginXmlCapitalization -->
220221
<action id="Flutter.Menu.RunProfileAction" class="io.flutter.actions.RunProfileFlutterApp"
221-
description="Flutter Run Profile Mode"
222+
description="Run Flutter app in profile mode"
223+
text="Run in Flutter Profile Mode"
222224
icon="AllIcons.Actions.Execute">
223225
</action>
224226
<!--suppress PluginXmlCapitalization -->
225227
<action id="Flutter.Menu.RunReleaseAction" class="io.flutter.actions.RunReleaseFlutterApp"
226-
description="Flutter Run Release Mode"
228+
description="Run Flutter app in release mode"
229+
text="Run in Flutter release mode"
227230
icon="AllIcons.Actions.Execute">
228231
</action>
229232
<reference ref="AttachDebuggerAction"/>

0 commit comments

Comments
 (0)