Guidelines / solution to run compiled version
Is your feature request related to a problem? Please describe.
The current execution of flutter pub run import_sorter:main has a slow start due to the Dart VM initialisation. While it is acceptable if it is ran infrequently (like as a GIT commit hook for example), it is a lot more critical when running frequently (like every time a file is saved for example).
Describe the solution you'd like
- Give users guidelines to use the natively compiled version of the library rather that its Dart version
- OR find a way to distribute the compiled versions
Describe alternatives you've considered I have tested the execution time of this library for three different versions:
- 1: The Dart version, as described in the README
- 2: The AOT compiled version, as described in https://dart.dev/tools/dart-compile#aot-snapshot
- 3: The executable compiled version, as described in https://dart.dev/tools/dart-compile#exe
Results:
- 1 was the slowest, with an initialisation time of about 1 to 2 seconds on a i9 2019 Macbook Pro 16'.
- 2 was faster, maybe twice faster.
- 3 was the fastest, almost instantaneous
Additional context The benefits of running a compiled version are also explained in https://dart.dev/tutorials/server/get-started#6-compile-for-production.
This is what I've done to get a nice experience using this lib:
- Compile to native code
dart compile exe bin/main.dart -o bin/import_sorter
- Add bin path to
PATH - Use lib in VSCode with https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave I've set it up with the following settings:
"emeraldwalk.runonsave": {
"commands": [
{
"match": "\\.dart$",
"cmd": "import_sorter ${file}"
}
]
}
Now every time I save a file in my IDE, the imports are organised instantaneously! This makes it a lot more enjoyable.
See #63