Skip to content

[perf] create action presentations lazily #8187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 13, 2025

Conversation

pq
Copy link
Contributor

@pq pq commented May 13, 2025

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

The only risk is in ensuring that the templated menu text is still getting properly filled in, and I confirmed that:

image


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

@pq pq requested review from jwren and helin24 May 13, 2025 20:46
@pq pq merged commit 1169f5e into flutter:master May 13, 2025
7 checks passed
@pq pq deleted the perf_eagerActionPresentation branch May 13, 2025 22:26
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.

3 participants