简体   繁体   中英

DART : Why dart apps are so big in size? (console app)

i made a console app with dart that calculates 2 numbers and prints them the size came about 5 MB !!

Download link (Windows only) https://drive.google.com/open?id=1sxlvlSZUdxewzFNiAv_bXwaUui2gs2yA

Here is the code

import 'dart:io';

int inputf1;
int inputf2;
int inputf3;

void main() {
  stdout.writeln('Type The First Number');
  var input1 = stdin.readLineSync();
  stdout.writeln('You typed: $input1 as the first number');
  sleep( Duration(seconds: 1));
  stdout.writeln('\nType The Second Number');
  var input2 = stdin.readLineSync();
  stdout.writeln('You typed: $input2 as the second number');
  sleep( Duration(seconds: 1));
  inputf1 = int.parse(input1);
  inputf2 = int.parse(input2);

  inputf3 = inputf1 + inputf2;
  print('\nfinal answer is : $inputf3');
  sleep( Duration(seconds: 10));
}

The reason for the big executable is because the dart2native compiler is not really made to make a executable you can directly run on your machine from scratch. Instead, it package the dartaotruntime executable together with your AOT compiled Dart program.

The dartaotruntime contains all the Dart runtime libraries and dart2native does not remove anything from the dartaotruntime (also difficult since it is a binary) so you will get the whole runtime even if you only adds two numbers.

But it is not that bad since it is an one-cost penalty for every program. So if you make a very big program, the dartaotruntime are still only include once.

However, if you are deploying many small programs in a single package I will recommend you add the -k aot parameter to dart2native so it instead of an executable will generate an .aot file which you then can run with dartaotruntime <program.aot> .

This will make your deployment a bit more complicated but you will just need to provide the dartaotruntime binary together with you multiple .aot files.

I have compiled your program to both .exe and .aot on Dart for Windows 64 bit. version 2.8.2 so you can see the size difference:

在此处输入图像描述

Again, -k aot will not save you any disk space if you are only going to deploy a single executable. But it can save a lot if your project contains many programs.

It should also be noted that the .aot file is platform dependent like the .exe file would be. And you should use the same version of dartaotruntime which has been used to compile the file.

It is because natively dart app are made by incorporate the render engine... I know that is right for all the flutter app which are based on dart. Look at this too https://medium.com/@rajesh.muthyala/app-size-in-flutter-5e56c464dea1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM