JIT JIT(Just In Time) 翻译为 即时编译,指的是在程序运行中,将热点代码编译成机器码,提升运行效率。常见例子有 V8 引擎和 JVM,JIT 能够充分利用解释型语言的优势,动态执行源码,而不用考虑平台差别性。这里须要注意的是,对于 JVM 来讲,源码指字节码,而不是 Java 源码。ios
AOT AOT(Ahead Of Time) 称为 运行前编译,指的是在程序运行以前,已经编译成对应平台的机器码,不须要在运行中解释编译,就能够直接运行。常见例子有 C 和 C++。 虽然,咱们会区别 JIT 和 AOT 两种编译模式,但实际上,有不少语言并非彻底使用 JIT 或者 AOT 的,一般它们会混用这两种模式,来达到最大的性能优化。性能优化
Script:最普通的 JIT模式,在 PC命令行调用 dart vm执行 dart源代码文件便是这种模式。bash
Script Snapshot:JIT模式,和上一个不一样的是,这里载入的是已经 token化的 dart源代码,提早执行了上一步的 lexer步骤。markdown
Application Snapshot:JIT模式,这种模式来源于 dart vm直接载入源码后 dump出数据。dart vm经过这种数据启动会更快。不过值得一提的是这种模式是区分架构的,在 x64上生成的数据不能够给 arm使用。架构
AOT:AOT模式,直接将 dart源码编译出 .S文件,而后经过汇编器生成对应架构的代码。app
Script:同 Dart Script模式一致,虽然 Flutter支持,但暂未看到使用,毕竟影响启动速度。性能
Kernel Snapshot:Dart的 bytecode 模式,bytecode模式是不区分架构的。Kernel Snapshot在 Flutter项目内也叫 Core Snapshot。bytecode模式能够归类为 AOT编译。优化
Core JIT:Dart的一种二进制模式,将指令代码和 heap数据打包成文件,而后在 vm和 isolate启动时载入,直接标记内存可执行,能够说这是一种 AOT模式。Core JIT也被叫作 AOTBlobui
AOT Assembly: 即 Dart的 AOT模式。直接生成汇编源代码文件,由各平台自行汇编。包体积比较大,区分架构。this
Android : Kernel Snapshot模式
iOS : Kernel Snapshot模式
Android : Core JIT
iOS : AOT Assembly
flutter build apk flutter build apk --debug flutter build ios flutter build ios —debug Usage: flutter build <subcommand> [arguments] -h, --help Print this usage information. Available subcommands: aot Build an ahead-of-time compiled snapshot of your app's Dart code. apk Build an Android APK file from your app. appbundle Build an Android App Bundle file from your app. bundle Build the Flutter assets directory from your app. ios Build an iOS application bundle (Mac OS X host only). 复制代码
Android产物就是build/app/intermediates/flutter/XXX下面的flutter_assets/目录中的全部内容。若是是release或者profile版本的话,还包含Dart的二进制产物app.so或者***snapshot***。能够看到,除了默认状况的***snapshot***,咱们还能够指定Dart产物为常规的so库形式。
isolate_snapshot_data :用于加速 isolate启动,业务无关代码,固定,仅和 flutter engine版本有关
vm_snapshot_data :用于加速 dart vm启动的产物,业务无关代码,仅和 flutter engine版本有关
kernel_blob.bin :JIT模式下Dart编译的中间代码
flutter.so :Flutter引擎
assets :资源文件
iOS产物 App.framework
Flutter相关代码的最终产物是:App.framework(dart代码生成)和Flutter.framework(引擎)。