Title: Enable modules snapshot for Android · Issue #1563 · NativeScript/NativeScript · GitHub
Open Graph Title: Enable modules snapshot for Android · Issue #1563 · NativeScript/NativeScript
X Title: Enable modules snapshot for Android · Issue #1563 · NativeScript/NativeScript
Description: The Story In a nutshell - since in Android application loading time is one of the areas that need improvement, we've made a POC implementation that takes advantage of V8's startup snapshots feature to see what may be achieved with it. Th...
Open Graph Description: The Story In a nutshell - since in Android application loading time is one of the areas that need improvement, we've made a POC implementation that takes advantage of V8's startup snapshots feature...
X Description: The Story In a nutshell - since in Android application loading time is one of the areas that need improvement, we've made a POC implementation that takes advantage of V8's startup snapshots...
Opengraph URL: https://github.com/NativeScript/NativeScript/issues/1563
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Enable modules snapshot for Android","articleBody":"# The Story\n\nIn a nutshell - since in Android application loading time is one of the areas that need improvement,\nwe've made a POC implementation that takes advantage of V8's [startup snapshots](http://v8project.blogspot.bg/2015/09/custom-startup-snapshots.html) feature to see what may be achieved with it. The results are quite promising and we may gain literally more than **1 second !** of an improvement by saving all the modules.\n# Technical Details\n\nDue to the V8 API specifics, we need to bundle the entire modules JS into one single file and pass it to the [V8::CreateSnapshotDataBlob](http://v8.paulfryzel.com/docs/master/classv8_1_1_v8.html#a05f6c30582cc654b5fb09fab98a0dbbb) method. What V8 does when making the snapshot is to parse, compile and run this script into a new Context and then to save the state of the heap into a binary representation. Then, upon next application runs, this binary file may be used to load the whole representation of the modules directly within memory. \n\nHere is my proposal for taking advantage of this feature:\n# Distribute pre-generated BLOBs\n\nThe snapshot is CPU-architecture dependent. Hence, if we want to distribute pre-generated version of the snapshot we will need to package three files, saved against the three available architectures - `armeabi-v7a`, `x86` and `arm64-v8a`. The average size of one file is ~3 MB but it compresses very well and an archived version is about 400 KB. \n\n**This is the most efficient way performance-wise. It adds further optimization by skipping the extraction of numerous JS files initially**\n# Tasks:\n- [x] Ensure modules are snapshot-ready. This is already done - https://github.com/NativeScript/NativeScript/pull/1407\n- [x] Write a custom bundler that puts all the modules content within a single JS file. I've already done a custom Node task for the POC but we may go with [webpack](https://webpack.github.io/) for example (as @hdeshev) suggested.\n- [x] Think how to automate snapshot generation against the three CPU architectures.\n- [x] Think how to distribute (package) these three binary files. For example we may have two packages - `tns-core-modules` and `tns-core-modules-snapshot`. Or we may package all into one package.\n- [x] Since the debugger does not work with snapshots, we will need to rely on the snapshot for release builds ONLY. Hence, there will be some effort on the CLI side. Plus, for release builds the CLI should not pack the modules JavaScript files but only the BLOBs (ping @teobugslayer, @ligaz).\n- [x] Enable the Android Runtime to consume such a BLOB directly, depending on the current CPU architecture. We may use the same convention as for the native part of the Runtime itself, for example:\n \n ```\n tns_modules\n ├── snapshot\n │ ├── armeabi-v7a\n │ │ ├── snapshot.blob\n │ ├── arm64-v8a\n │ │ ├── snapshot.blob\n │ ├── x86\n │ │ ├── snapshot.blob\n \n ```\n","author":{"url":"https://github.com/atanasovg","@type":"Person","name":"atanasovg"},"datePublished":"2016-02-16T16:56:25Z","url":"https://github.com/NativeScript/NativeScript/issues/1563"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:fb45dc58-4fd9-7a0e-42be-7b9641fc15e4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D24C:38E318:F72F6B:1372F2C:6B014730 |
| html-safe-nonce | b9f1945e4fd9a7c18fb302a02101822045ba9e1680cd9d074084ec3264501b02 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMjRDOjM4RTMxODpGNzJGNkI6MTM3MkYyQzo2QjAxNDczMCIsInZpc2l0b3JfaWQiOiI0MzE0MTMxODI4NDE3MDU0NTEyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 101d49a3b9d5014c50759fd9e8527d504a2a7686d25b95b9d0cda55085ab969a |
| hovercard-subject-tag | issue:134034614 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/NativeScript/NativeScript/1563/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1012f072863d10223e36c68ae0ca45533d7cefba352f53d66b60de873b157bcc/NativeScript/NativeScript/issues/1563 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1012f072863d10223e36c68ae0ca45533d7cefba352f53d66b60de873b157bcc/NativeScript/NativeScript/issues/1563 |
| og:image:alt | The Story In a nutshell - since in Android application loading time is one of the areas that need improvement, we've made a POC implementation that takes advantage of V8's startup snapshots feature... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | atanasovg |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/NativeScript/NativeScript git https://github.com/NativeScript/NativeScript.git |
| octolytics-dimension-user_id | 7392261 |
| octolytics-dimension-user_login | NativeScript |
| octolytics-dimension-repository_id | 31492490 |
| octolytics-dimension-repository_nwo | NativeScript/NativeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 31492490 |
| octolytics-dimension-repository_network_root_nwo | NativeScript/NativeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width