dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.26k stars 1.58k forks source link

Shrink size of dart2native EXE files #43512

Closed PetaSoft closed 4 years ago

PetaSoft commented 4 years ago

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 command cargo 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 command cl.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.

mraleph commented 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.

YarosMallorca commented 1 year ago

How is this still not fixed?