# Embedding V8 in NativeScript - Vladimir Mutafov
###### tags: `jsdc2019`
{%hackmd @JSDC-tw/2019-announcement %}
[講者 github](https://github.com/vmutafov)
## [NativeScript](https://www.nativescript.org/)
Open source framework for building truly native mobile apps with Angular, Vue.js, TypeScript, or JavaScript.
### NativeScript Magic
- JS code
- N Runtime
- V8
### Application launch
啟動 V8 -> 讀取 Metadata > 觸發 Callbacks
### JNI(Java Native Interface)
V8 (NativeScript Runtime) <=> ART (Android Runtime)
v8:OobjectTemplate::
### Marshalling
```
java.lang.String !== string
```
Convert data type between Java and Javascript.
Java objects are proxied to special JS objects.
### Objects lifecycle
- garbage collection (Both V8 and Android Runtime have)
**problem:** garbage collector doesn't know when should stop so it need sync.
Sync by nativescript runtime
#### Out of Memory exceptions
JS proxy object is smaller
1. v8::Isolate::
2. forcing garbage collection (not good)
3. `releaseNativeCounterpart(jsImage)`
#### Multithreading
Mobile Application need 60 fps
Worker threads for CPU intensive work (isolate in v8)
one islolation = multiple contexts
#### Context
Worker Thread = isolate
### SnapShot
- FS request (performance issue, very slow)
- solution: bundle
- snapshot limitation: build snapshot at build time → no Android information (e.g. android.os.Build.Version.SDK.INT ⇒ use getter to avoid error!)
#### loading snapshots
**problem:** No Native API
@StanimiraVlaeva
@VladimirMutafov
### Q&A
2. How to Debugging
3. Marshalling
4. v8 provide native Interface APIs for UI?
## Example (iOS)
1. [下載 Nativescript Preview](https://apps.apple.com/tw/app/nativescript-preview/id1264484702)
2. [去這裡隨便選個 Sample](https://market.nativescript.org/?tab=samples&framework=vue&category=all_samples&_ga=2.57672618.1022828759.1572057055-1905761369.1572057055)
3. 用 Nativescript Preview 掃 QR Code
4. 開始開發!