Skip to content

Commit 894af53

Browse files
authored
[perf] stop static initialization in line marker extension (#8114)
![image](https://github.com/user-attachments/assets/bffce434-6527-4501-95d7-129541d8b4b7) From the inspection description: > Static initialization is performed once the class is loaded, which may cause excessive classloading or early initialization of heavy resources. Since extension point implementations are supposed to be cheap to create, they must not have static initializers. --- - [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](#8098)). </details>
1 parent afb700d commit 894af53

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

flutter-idea/src/io/flutter/editor/FlutterIconLineMarkerProvider.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,16 @@ public class FlutterIconLineMarkerProvider extends LineMarkerProviderDescriptor
5555
private static final String CupertinoRelativeAssetPath = "/assets/CupertinoIcons.ttf";
5656
private static final String CupertinoRelativeIconsPath = "/packages/flutter/lib/src/cupertino/icons.dart";
5757

58-
static {
59-
initialize();
58+
private static boolean instantiated = false;
59+
60+
FlutterIconLineMarkerProvider() {
61+
// Extension point implementations can't use static initializers so we keep track of the
62+
// first instantiation to make sure #initialize is called to set up initial state. (Note that this state
63+
// may get reset with a subsequent explicit call to #initialize.)
64+
if (!instantiated) {
65+
initialize();
66+
}
67+
instantiated = true;
6068
}
6169

6270
public static void initialize() {

0 commit comments

Comments
 (0)