{"id":253,"date":"2023-10-12T01:18:17","date_gmt":"2023-10-11T17:18:17","guid":{"rendered":"http:\/\/www.sourcecool.com\/?p=253"},"modified":"2023-10-12T01:18:17","modified_gmt":"2023-10-11T17:18:17","slug":"flutterdebianyimoshi","status":"publish","type":"post","link":"http:\/\/www.sourcecool.com\/index.php\/2023\/10\/12\/flutterdebianyimoshi\/","title":{"rendered":"Flutter\u7684\u7f16\u8bd1\u6a21\u5f0f"},"content":{"rendered":"\n<p>\u4f7f\u7528\u8fc7 Flutter \u6784\u5efa APP \u7684\u4eba\u53ef\u80fd\u6709\u4e2a\u7591\u60d1\uff0cFlutter \u7684\u7f16\u8bd1\u4ea7\u7269\u6709\u65f6\u5019\u662f\u4e00\u4e2a\u5171\u4eab\u5e93\uff0c\u6709\u65f6\u5019\u662f\u51e0\u4e2a\u6587\u4ef6\uff0c\u6bd4\u8f83\u96be\u4e8e\u7406\u89e3\uff0c\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd Flutter \u4e2d\u7684\u7f16\u8bd1\u6a21\u5f0f\u3002<\/p>\n\n\n\n<h2>\u7f16\u8bd1\u6a21\u5f0f\u5206\u7c7b<\/h2>\n\n\n\n<p>\u6e90\u4ee3\u7801\u9700\u8981\u7f16\u8bd1\u624d\u80fd\u8fd0\u884c\uff0c\u4e00\u822c\u6765\u8bb2\u7f16\u8bd1\u6a21\u5f0f\u5206\u4e3a JIT \u548c AOT \u4e24\u5927\u7c7b<\/p>\n\n\n\n<h3>JIT<\/h3>\n\n\n\n<p>\u5168\u79f0\u4e3a Just In Time(\u5373\u65f6\u7f16\u8bd1)\uff0c\u6bd4\u8f83\u5178\u578b\u7684\u5c31\u662f V8 JS\u5f15\u64ce\uff0c\u5b83\u80fd\u591f\u5373\u65f6\u7684\u7f16\u8bd1\u548c\u8fd0\u884c JavaScript \u4ee3\u7801\u3002\u4f60\u53ea\u8981\u8f93\u5165 JavaScript \u7684\u5b57\u7b26\u4e32\u6e90\u7801\uff0cV8 \u5c31\u80fd\u7f16\u8bd1\u548c\u8fd0\u884c\u8fd9\u6bb5\u4ee3\u7801\u3002\u901a\u5e38\u6765\u8bf4\uff0c\u652f\u6301 JIT \u7684\u8bed\u8a00\u4e00\u822c\u80fd\u591f\u652f\u6301\u81ea\u7701\u51fd\u6570\uff08eval\uff09\uff0c\u5728\u8fd0\u884c\u65f6\u52a8\u6001\u7684\u6267\u884c\u6e90\u7801\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5 JIT \u6a21\u5f0f\u6709\u4e2a\u663e\u7136\u7684\u4f18\u70b9\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u5c06\u4ee3\u7801\u5206\u53d1\u7ed9\u7528\u6237\uff0c\u800c\u4e0d\u7528\u8003\u8651\u7528\u7684\u673a\u5668\u67b6\u6784\u3002\u6709\u8fd9\u4e2a\uff0c\u5c31\u53ef\u4ee5\u4e3a\u7528\u6237\u63d0\u4f9b\u4e30\u5bcc\u548c\u52a8\u6001\u7684\u5185\u5bb9\u3002<\/p>\n\n\n\n<p>\u4f46\u7f3a\u70b9\u4e5f\u662f\u6bd4\u8f83\u660e\u663e\u7684\uff0c\u5927\u91cf\u7684\u5b57\u7b26\u4e32\u6e90\u7801\uff0c\u5c06\u82b1\u8d39 JIT \u7f16\u8bd1\u5668\u5927\u91cf\u7684\u65f6\u95f4\u548c\u5185\u5b58\u6765\u7f16\u8bd1\u548c\u6267\u884c\uff0c\u4f1a\u8ba9\u7528\u6237\u611f\u89c9\u5e94\u7528\u542f\u52a8\u7f13\u6162\u3002<\/p>\n\n\n\n<h3>AOT<\/h3>\n\n\n\n<p>\u5168\u79f0\u4e3a Ahead Of Time(\u4e8b\u524d\u7f16\u8bd1), \u5178\u578b\u7684\u4f8b\u5b50\u5c31\u662f\u50cf C\/C++ \u9700\u8981\u88ab\u7f16\u8bd1\u6210\u7279\u6b8a\u7684\u4e8c\u8fdb\u5236\uff0c\u624d\u53ef\u4ee5\u901a\u8fc7\u8fdb\u7a0b\u52a0\u8f7d\u548c\u8fd0\u884c\u3002<\/p>\n\n\n\n<p>AOT \u7684\u4f18\u52bf\u5c31\u662f\u901f\u5ea6\u5feb\uff0c\u901a\u8fc7\u4e8b\u5148\u7f16\u8bd1\u597d\u7684\u4e8c\u8fdb\u5236\u4ee3\u7801\uff0c\u52a0\u8f7d\u548c\u6267\u884c\u7684\u901f\u5ea6\u90fd\u4f1a\u975e\u5e38\u5feb\uff0c\u5728\u5bc6\u96c6\u8ba1\u7b97\u6216\u8005\u56fe\u5f62\u6e32\u67d3\u7684\u573a\u666f\u4e0b\u80fd\u591f\u83b7\u5f97\u6bd4\u8f83\u597d\u7684\u7528\u6237\u4f53\u9a8c\u3002<\/p>\n\n\n\n<p>\u4f46 AOT \u4e5f\u6709\u4e00\u4e9b\u7f3a\u70b9\uff0c\u7f16\u8bd1\u6e90\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u9700\u8981\u6ce8\u610f\u7528\u6237\u7684\u8bbe\u5907\u67b6\u6784\u3002\u5bf9\u4e8e\u4e0d\u540c\u7684\u6784\u67b6\u9700\u8981\u751f\u6210\u4e0d\u540c\u7684\u4e8c\u8fdb\u5236\u4ee3\u7801\uff0c\u4e5f\u5c31\u4f1a\u589e\u52a0\u5e94\u7528\u9700\u8981\u4e0b\u8f7d\u7684\u7a0b\u5e8f\u5305\u5927\u5c0f\u3002\u800c\u4e14\u4e8c\u8fdb\u5236\u4ee3\u7801\u9700\u8981\u83b7\u5f97\u6267\u884c\u6743\u9650\uff0c\u6240\u4ee5\u65e0\u6cd5\u5728\u6743\u9650\u6bd4\u8f83\u4e25\u683c\u7684\u7cfb\u7edf(\u6bd4\u5982iOS)\u4e2d\u52a8\u6001\u66f4\u65b0\u3002<\/p>\n\n\n\n<h2>Dart \u7684\u7f16\u8bd1\u6a21\u5f0f<\/h2>\n\n\n\n<p>Flutter \u4f7f\u7528 Dart \u4f5c\u4e3a\u5f00\u53d1\u8bed\u8a00\uff0c\u81ea\u7136\u548c Dart \u7684\u7f16\u8bd1\u6a21\u5f0f\u8131\u79bb\u4e0d\u4e86\u5173\u7cfb\uff0c\u6240\u4ee5\u6211\u4eec\u5148\u6765\u770b\u4e00\u4e0b Dart \u7684\u7f16\u8bd1\u6a21\u5f0f\u3002<\/p>\n\n\n\n<p><em><strong>Script:<\/strong>&nbsp;\u6700\u5e38\u89c1\u7684 JIT \u6a21\u5f0f\uff0c\u5c31\u50cf Node.js \u90a3\u6837\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u76f4\u63a5\u6267\u884c Dart \u6e90\u4ee3\u7801<\/em><\/p>\n\n\n\n<p><strong><em>Script Snapshot<\/em>:<\/strong>&nbsp;\u4e0d\u540c\u4e8e Script \u6a21\u5f0f\uff0cScript Snapshot \u6a21\u5f0f\u8f7d\u5165\u7684\u662f\u5df2\u7ecf token \u5316\u7684 dart \u6e90\u7801\uff0c\u63d0\u524d\u505a\u4e86\u7f16\u8bd1\u671f\u95f4\u7684 Lexer \u6b65\u9aa4, \u4e5f\u662f\u5c5e\u4e8e JIT \u6a21\u5f0f<\/p>\n\n\n\n<p><em><strong>Application Snapshot:<\/strong>&nbsp;JIT \u6a21\u5f0f\uff0c\u8fd9\u79cd\u6a21\u5f0f\u6765\u6e90\u4e8e dart vm\u76f4\u63a5\u8f7d\u5165\u6e90\u7801\u540e dump \u51fa\u6570\u636e\u3002dart vm \u901a\u8fc7\u8fd9\u79cd\u6570\u636e\u542f\u52a8\u4f1a\u66f4\u5feb\u3002\u4e0d\u8fc7\u8fd9\u79cd\u6a21\u5f0f\u662f\u533a\u5206\u67b6\u6784\u7684\uff0c\u5728 X64 \u4e0b\u751f\u6210\u7684\u65e0\u6cd5\u7ed9 IA_32 \u7528<\/em><\/p>\n\n\n\n<p><strong><em>AOT<\/em>:<\/strong>&nbsp;AOT \u6a21\u5f0f\uff0cdart \u6e90\u4ee3\u7801\u4f1a\u88ab\u7f16\u8bd1\u6210\u6c47\u7f16\u6587\u4ef6\uff0c\u6c47\u7f16\u518d\u7ecf\u8fc7\u6c47\u7f16\u5668\u751f\u6210\u4e0d\u540c\u67b6\u6784\u4e0b\u7684\u4e8c\u8fdb\u5236\u4ee3\u7801<\/p>\n\n\n\n<p>\u7528\u8868\u683c\u603b\u7ed3\u4e00\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic1.zhimg.com\/80\/v2-3d59564769990d3cc6422fcadc3d24ec_1440w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<h2>Flutter \u7684\u7f16\u8bd1\u6a21\u5f0f<\/h2>\n\n\n\n<p>Flutter \u7a0b\u5e8f\u5b8c\u5168\u7528 Dart, \u7406\u8bba\u4e0a Flutter \u7684\u7f16\u8bd1\u6a21\u5f0f\u5e94\u8be5\u548c Dart \u7684\u4e00\u81f4\uff0c\u4e8b\u5b9e\u4e0a\u56e0\u4e3a Android \u548c iOS \u751f\u6001\u7684\u5dee\u5f02\uff0cFlutter \u884d\u751f\u4e86\u4e0d\u540c\u7684\u7f16\u8bd1\u6a21\u5f0f\u3002<\/p>\n\n\n\n<p><em><strong>Script:<\/strong>&nbsp;\u548c Dart \u7684 Script \u6a21\u5f0f\u4e00\u6837\uff0c\u4f46\u662f\u6ca1\u6709\u5f00\u542f\u4f7f\u7528<\/em><\/p>\n\n\n\n<p><strong><em>Script Snapshot<\/em>:<\/strong>&nbsp;\u4e5f\u662f\u548c Dart \u7684 Script Snapshot \u6a21\u5f0f\u4e00\u6837\uff0c\u4e5f\u6ca1\u6709\u5f00\u542f\u4f7f\u7528<\/p>\n\n\n\n<p><em><strong>Kernel Snapshot:<\/strong>&nbsp;Dart \u7684 bytecode \u6a21\u5f0f\uff0c\u5728\u67d0\u79cd\u7a0b\u5ea6\u4e0a\u7c7b\u4f3c JVM\u3002\u5728 Flutter \u9879\u76ee\u4e2d\u4e5f\u88ab\u53eb\u505a Core Snapshot\uff0c\u5b83\u662f\u548c\u8bbe\u5907\u67b6\u6784\u65e0\u5173\u7684<\/em><\/p>\n\n\n\n<p><strong><em>Core JIT<\/em>:<\/strong>&nbsp;\u4e00\u79cd\u7f16\u8bd1\u540e\u7684\u4e8c\u8fdb\u5236\u683c\u5f0f\uff0c\u7a0b\u5e8f\u7684\u6570\u636e\u548c\u6307\u4ee4\u88ab\u6253\u5305\u6210\u7279\u6b8a\u7684\u4e8c\u8fdb\u5236\uff0c\u5728\u8fd0\u884c\u65f6\u52a0\u8f7d\u3002\u4e8b\u5b9e\u4e0aCore JIT \u4e5f\u88ab\u53eb\u505a AOT Blobs, \u662f AOT \u7684\u4e00\u79cd<\/p>\n\n\n\n<p><strong><em>AOT Assembly<\/em>:<\/strong>&nbsp;\u548c Dart \u7684 AOT \u6a21\u5f0f\u4e00\u6837<\/p>\n\n\n\n<p>\u6240\u4ee5\u5728 Flutter \u91cc\u4f1a\u66f4\u590d\u6742\u4e00\u70b9\uff0c\u6211\u4eec\u7ed3\u5408 Flutter \u7684\u5404\u4e2a\u5f00\u53d1\u9636\u6bb5\u6765\u89e3\u8bfb\u4e00\u4e0b\u3002<\/p>\n\n\n\n<h3>\u5f00\u53d1\u9636\u6bb5<\/h3>\n\n\n\n<p>\u5f00\u53d1 Flutter APP \u7684\u65f6\u5019\uff0c\u6211\u4eec\u9700\u8981 HOT Reload \u65b9\u4fbf UI \u5feb\u901f\u6210\u578b\uff0c\u540c\u65f6\u4e5f\u9700\u8981\u6bd4\u8f83\u9ad8\u7684\u6027\u80fd\u6765\u8fdb\u884c\u89c6\u56fe\u6e32\u67d3\uff0c\u6240\u4ee5 Flutter \u5728 Debug \u4e0b\u4f7f\u7528\u4e86 Kernel Snapshot \u7f16\u8bd1\u6a21\u5f0f\uff0c\u4f1a\u751f\u6210\u5982\u4e0b\u4ea7\u7269\uff1a<\/p>\n\n\n\n<p><em><strong>isolate_snapshot_data:<\/strong>&nbsp;\u52a0\u901f isolate \u542f\u52a8\u7684\u6570\u636e\uff0c\u548c\u4e1a\u52a1\u65e0\u5173<\/em><\/p>\n\n\n\n<p><strong><em>vm_snapshot_data<\/em>:&nbsp;<\/strong>\u52a0\u901f Dart VM \u542f\u52a8\u7684\u6570\u636e\uff0c\u548c\u4e1a\u52a1\u65e0\u5173<\/p>\n\n\n\n<p><strong><em>kernel_blob.bin<\/em>:&nbsp;<\/strong>\u4e1a\u52a1\u4ee3\u7801\u4ea7\u7269<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic3.zhimg.com\/80\/v2-170fd9b46e3207b8ebf717ffd64b775e_1440w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<h3>\u53d1\u5e03\u9636\u6bb5<\/h3>\n\n\n\n<p>\u5728\u751f\u4ea7\u9636\u6bb5\uff0c\u5e94\u7528\u9700\u8981\u975e\u5e38\u5feb\u7684\u901f\u5ea6\u3002\u6240\u4ee5 Flutter \u4f7f\u7528\u4e86 AOT \u7f16\u8bd1\u6a21\u5f0f\uff0c\u4f46\u662f\u5728\u4e0d\u540c\u7684\u5e73\u53f0\u4e0b\uff0c\u8fd8\u662f\u6709\u4e9b\u4e0d\u4e00\u6837\u7684<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic1.zhimg.com\/80\/v2-0fd58b60ebb02540edff3fb99f1e4120_1440w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u5728 iOS \u5e73\u53f0\u7531\u4e8e App Store \u5ba1\u6838\u6761\u4f8b\u4e0d\u5141\u8bb8\u52a8\u6001\u4e0b\u53d1\u53ef\u6267\u884c\u4e8c\u8fdb\u5236\u4ee3\u7801\uff0c\u6240\u4ee5\u5728 iOS \u4e0a\uff0c\u9664\u4e86 JavaScript\uff0c\u5176\u4ed6\u8bed\u8a00\u90fd\u4f7f\u7528 AOT \u7f16\u8bd1\u3002<\/p>\n\n\n\n<p>\u4f46\u662f\u5728 Android \u5e73\u53f0\u4e0a\uff0cCore JIT \u548c AOT Assembly \u90fd\u652f\u6301\u4e86\uff0c\u5728 Core JIT \u6a21\u5f0f\u4e0b\u4f1a\u751f\u6210\u56db\u4e2a\u4ea7\u7269\uff1aisolate_snapshot_data\/vm_snapshot_data\/isolate_snapshot_instr\/vm_snapshot_instr<\/p>\n\n\n\n<p>vm_snapshot_instr \u548c isolate_snapshot_instr \u662f Dart VM \u548c isolate \u7684\u6307\u4ee4\uff0c\u5728\u8f7d\u5165\u540e\uff0c\u76f4\u63a5\u5c06\u8be5\u5757\u5185\u5b58\u6267\u884c\u5373\u53ef\u3002<\/p>\n\n\n\n<p>isolate_snapshot_data \u548c vm_snapshot_data \u662f Dart VM \u548c isolate \u7684\u542f\u52a8\u6570\u636e\uff0c\u4e3b\u8981\u662f\u4e3a\u4e86\u52a0\u901f\u542f\u52a8\u901f\u5ea6\u3002<\/p>\n\n\n\n<h3>Flutter Engine \u652f\u6301\u60c5\u51b5<\/h3>\n\n\n\n<p>Flutter Engine \u5305\u542b\u4e86 Dart \u7684\u8fd0\u884c\u65f6\uff0cFlutter \u5e94\u7528\u7684\u7f16\u8bd1\u4ea7\u7269\u5fc5\u987b\u548c Engine \u5339\u914d\u624d\u884c\uff0cEngine \u5728\u4e0d\u540c\u7684\u9636\u6bb5\u63d0\u4f9b\u4e86\u4e0d\u540c\u7684\u652f\u6301<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic3.zhimg.com\/80\/v2-c71be21bf934498fe6e5ac034cd75fa2_1440w.webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u901a\u8fc7 gen_snapshot -h \u4e5f\u53ef\u4ee5\u67e5\u770b\u5230\uff0cEngine \u5bf9\u7f16\u8bd1\u6a21\u5f0f\u7684\u652f\u6301\uff0c\u4e8b\u5b9e\u4e0a Dart \u6e90\u7801\u5c31\u662f\u7ecf\u8fc7 gen_snapshot \u53bb\u5904\u7406\u7684\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>To create a core snapshot:                                                  \n--snapshot_kind=core                                                        \n--vm_snapshot_data=&lt;output-file&gt;                                            \n--isolate_snapshot_data=&lt;output-file&gt;                                       \n&lt;dart-kernel-file&gt;                                                          \n                                                                            \nTo create an AOT application snapshot as assembly suitable for compilation  \nas a static or dynamic library:                                             \n--snapshot_kind=app-aot-assembly                                            \n--assembly=&lt;output-file&gt;                                                    \n&#91;--obfuscate]                                                               \n&#91;--save-obfuscation-map=&lt;map-filename&gt;]                                     \n&lt;dart-kernel-file&gt;                                                          \n                                                                            \nTo create an AOT application snapshot as an ELF shared library:             \n--snapshot_kind=app-aot-elf                                                 \n--elf=&lt;output-file&gt;                                                         \n&#91;--strip]                                                                   \n&#91;--obfuscate]                                                               \n&#91;--save-obfuscation-map=&lt;map-filename&gt;]                                     \n&lt;dart-kernel-file&gt;                                                          \n                                                                            \nAOT snapshots can be obfuscated: that is all identifiers will be renamed    \nduring compilation. This mode is enabled with --obfuscate flag. Mapping     \nbetween original and obfuscated names can be serialized as a JSON array     \nusing --save-obfuscation-map=&lt;filename&gt; option. See dartbug.com\/30524       \nfor implementation details and limitations of the obfuscation pass.      <\/code><\/pre>\n\n\n\n<p>AOT snapshots \u4e5f\u53ef\u4ee5\u4f7f\u7528 obfuscated \u9009\u9879\u5f00\u542f\u6df7\u6dc6, &#8211;save-obfuscation-map=&lt;filename&gt; \u4fdd\u5b58\u7b26\u53f7 mapping \u6587\u4ef6\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic3.zhimg.com\/80\/v2-b66c685af850f1a2278c3bfc819ca4ca_1440w.webp\" alt=\"\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528\u8fc7 Flutter \u6784\u5efa &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":[],"categories":[14],"tags":[],"_links":{"self":[{"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/posts\/253"}],"collection":[{"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/comments?post=253"}],"version-history":[{"count":1,"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/posts\/253\/revisions"}],"predecessor-version":[{"id":254,"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/posts\/253\/revisions\/254"}],"wp:attachment":[{"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/media?parent=253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/categories?post=253"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/tags?post=253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}