NativeScript for Mobile App Development Performance and Debugging 2 — Questions and Answers
Question 1: What causes UI jank in NativeScript applications?
- Running heavy computations synchronously on the main (UI) thread (Correct answer)
- Using too many plugins
- Having too many routes defined
- Using TypeScript instead of JavaScript
Correct answer: Running heavy computations synchronously on the main (UI) thread
Blocking the main thread with CPU-intensive tasks delays UI rendering, causing dropped frames and visible jank.
Question 2: Which NativeScript API runs code in a background thread?
- Worker API (new Worker()) (Correct answer)
- setTimeout with 0ms delay
- setImmediate()
- async/await
Correct answer: Worker API (new Worker())
NativeScript's Worker API (following the Web Workers spec) creates a true background thread to run CPU-intensive JavaScript without blocking the UI.
Question 3: What is the purpose of tree shaking in a NativeScript webpack build?
- Remove unused JavaScript code from the bundle to reduce app size (Correct answer)
- Optimize image assets
- Remove unused CSS rules
- Prune unused native dependencies
Correct answer: Remove unused JavaScript code from the bundle to reduce app size
Tree shaking statically analyzes imports and removes exported code that is never imported or used, reducing the JavaScript bundle size.
Question 4: Which NativeScript ListView optimization recycles view cells to improve scroll performance?
- Cell/view recycling via the itemTemplates and key template mechanism (Correct answer)
- Lazy data loading only
- Virtual DOM diffing
- GPU-accelerated rendering
Correct answer: Cell/view recycling via the itemTemplates and key template mechanism
ListView recycles a fixed pool of view cells, reusing them with new data as the user scrolls rather than creating new views for every item.
Question 5: What does the `--clean` flag do when running `ns build`?
- Deletes the platforms folder and rebuilds native projects from scratch (Correct answer)
- Clears the webpack cache only
- Removes node_modules
- Resets the app's local storage
Correct answer: Deletes the platforms folder and rebuilds native projects from scratch
`ns build android --clean` deletes the generated Android platform folder and performs a full native rebuild, useful for resolving stale build artifacts.
Question 6: Which profiling tool measures rendering performance of NativeScript iOS apps?
- Xcode Instruments (Time Profiler) (Correct answer)
- Chrome DevTools Performance tab
- Android Studio CPU Profiler
- ns profile ios
Correct answer: Xcode Instruments (Time Profiler)
Xcode Instruments provides Time Profiler and other tools to measure CPU usage, memory allocation, and rendering performance for iOS NativeScript apps.
What causes UI jank in NativeScript applications?