Google Flutter Google Flutter Performance 2 — Questions and Answers
Question 1: Which Flutter build mode should you always use when profiling app performance?
- Debug mode
- Release mode
- Profile mode (Correct answer)
- JIT mode
Correct answer: Profile mode
Profile mode compiles the app with AOT while keeping profiling hooks enabled, giving realistic performance numbers without debug overhead.
Question 2: What is the main benefit of using ListView.builder over ListView for large lists?
- ListView.builder supports horizontal scrolling
- ListView.builder lazily builds only visible items, reducing memory and build time (Correct answer)
- ListView.builder supports item reordering
- ListView.builder uses less code
Correct answer: ListView.builder lazily builds only visible items, reducing memory and build time
ListView.builder constructs items on demand as they scroll into view, avoiding building all items upfront for long lists.
Question 3: How does the cached_network_image package improve Flutter app performance?
- It pre-compresses images server-side
- It caches downloaded images on disk and memory to avoid redundant network requests (Correct answer)
- It converts images to WebP automatically
- It streams images in chunks for faster display
Correct answer: It caches downloaded images on disk and memory to avoid redundant network requests
cached_network_image stores downloaded images in a local cache, serving them instantly on repeat displays without hitting the network.
Question 4: What is the purpose of compute() in Flutter?
- To schedule a widget rebuild on the next frame
- To run a heavy computation on a separate isolate without blocking the UI thread (Correct answer)
- To precompute widget layouts
- To cache the result of a pure function
Correct answer: To run a heavy computation on a separate isolate without blocking the UI thread
compute() spawns a new isolate to run a function, keeping expensive work off the main UI thread to prevent jank.
Question 5: Which Flutter widget efficiently builds a large list where all children have the same height?
- ListView
- ListView.builder with itemExtent (Correct answer)
- GridView
- SingleChildScrollView with Column
Correct answer: ListView.builder with itemExtent
Setting itemExtent on ListView.builder tells Flutter the exact height of each item, enabling O(1) scroll position calculations instead of layout passes.
Question 6: What is tree shaking in the context of a Flutter release build?
- Removing unused widget subtrees at runtime
- Eliminating unused Dart code and assets from the compiled binary to reduce app size (Correct answer)
- Cleaning up the widget tree before hot reload
- Garbage collecting old widget instances
Correct answer: Eliminating unused Dart code and assets from the compiled binary to reduce app size
Tree shaking analyzes the dependency graph at compile time and strips out code that is never referenced, shrinking the final APK/IPA.
Which Flutter build mode should you always use when profiling app performance?