Closed PetaSoft closed 4 years ago
Thanks for taking time to report the issue. We are aware that the size of compiled "Hello, World!" is not as small as it could be, but we don't really think that "Hello, World!" is that much of an important metric. While it is true that resulting binary might contain some unused stuff due to the way things are currently set up (e.g. most of the dart:io
native parts are linked in even though Hello, World will never need them), however any more or less realistic application would actually use a lot of those parts. We have some plans to modularize things more, but nothing immediate.
How is this still not fixed?
I used dart2native to figure out the size of the created EXE file. I used a simple hello world dart source file and applied the command
dart2native helloworld.dart -k exe -o .\helloworld.exe
. I ran the command on Windows 10 x64 (2004) Professional. Unfortunately, the created EXE file was 4842 KB in size. That is far more than I expected. I suppose that the complete dart runtime is copied into the EXE file. I think that there exist a smarter way of compiling the source code to a much smaller EXE file using tree shaking and leaving everything not necessary for the functioning of the program outside of the EXE file. To support my assumption I made some other tests:1) I used Kotlin Native with a similar hello world source file and appied the command
kotlinc-native hello.kt -o hello
. The returned EXE file was 571 KB in size. Here, I want to ampersize that Kotlin also uses a garbage collector similar to dart and the runtime must be compiled into the EXE file. Therefore, both are really comparable. 2) I used Rust with a similar hello world source file and applied the commandcargo build --release
. The returned EXE file was 174 KB in size. As Rust does not use a garbage collector, the shrink in size was expectable. 3) I used the Visual Studio 2019 Build Tools and the Visual C++ Compiler with a similar C++ source file. I applied the commandcl.exe /O1 /MD /Fe: helloworld.exe hellloworld.cpp
. The returned EXE file was 11 KB in size, and I think that this a really good result for a simple helllo world program. Unfortunely, the cometitors did a worse job, and dart delivered the worst result.Once again, please think about the compilation process, and I would be glad to see smaller compilation results in the future. I am always delighted of small output files for small programs.