Performance Questions with Answers

14 practice questions on Performance (Flutter & Dart) with answers and step-by-step solutions. Try 10 samples below, then practise all 14 free in the AptiNest app.

Sample questions

Question 1Easy

Why does splitting a huge build method into smaller widget classes help performance?

  1. Small widgets rebuild on their own, so less is rebuilt
  2. It does not help performance; it only changes code readability
  3. Smaller widgets are compiled with a faster optimisation level
  4. Widget classes are cached on disk between application launches

Answer: A. Small widgets rebuild on their own, so less is rebuilt

Explanation

With separate widgets, setState or a dependency change can rebuild only the affected widget, and const subtrees can be skipped entirely.

Step-by-step solution

  1. When a widget's state or inputs change, Flutter rebuilds that widget's build method.
  2. A small widget class can rebuild on its own, so the rest of the tree is skipped.
  3. So splitting the build method helps performance, which is option A.

Why the other options are wrong

  • B. It does help: fewer widgets rebuild on each change.
  • C. The optimisation level is not the reason; the benefit is fewer rebuilds.
  • D. Widget classes are not cached on disk between launches.

Tip: Move parts of the UI that change often into their own widget class.

Question 2Easy

At 60 frames per second, roughly how long does Flutter have to build and render each frame?

  1. About 60 ms
  2. About 1 ms
  3. About 100 ms
  4. About 16 ms

Answer: D. About 16 ms

Explanation

1000 ms / 60 frames is about 16.7 ms per frame. Exceeding it causes dropped frames, seen as jank.

Step-by-step solution

  1. Total time in a second is 1000 ms.
  2. Divide 1000 ms by 60 to get per frame time: 1000 / 60 = 16.7.
  3. Flutter needs to build and render each frame within 16.7 ms.
  4. Rounded, this is about 16 ms per frame.
  5. Final answer: About 16 ms.

Why the other options are wrong

  • A. Sixty is the frame count, not milliseconds; 1000 ms divided by 60 gives about 16 ms per frame.
  • B. 1 ms would be 1000 frames per second; the budget is about 16 ms per frame at 60 fps.
  • C. 100 ms is about 10 frames per second, far too slow for 60 fps smoothness.

Tip: Use 1000 / frame rate to calculate time per frame.

Question 3Easy

What is "jank" in a Flutter app?

  1. Widgets that are drawn outside the visible screen area
  2. Unused packages that are left in the pubspec.yaml file
  3. Visible stutter from frames that take too long
  4. Warnings printed in the console during a debug build

Answer: C. Visible stutter from frames that take too long

Explanation

When a frame misses its time budget, the screen skips it and motion looks choppy.

Step-by-step solution

  1. Flutter targets a frame rate of 60 frames per second.
  2. Each frame has a strict time budget of about 16 milliseconds.
  3. If a frame takes longer than this budget, it is dropped.
  4. Dropped frames cause visible stutter or lag on the screen.
  5. This visual stutter is specifically called jank in Flutter.

Why the other options are wrong

  • A. Off-screen widgets are not jank; jank means slow visible frames.
  • B. Unused packages are a cleanup issue, not jank; jank is about frame timing.
  • D. Console warnings are not jank; jank describes visible stutter from slow frames.

Tip: Use the Flutter DevTools performance tab to identify and fix jank.

Question 4Easy

Why is it recommended to mark widgets const where possible, as in const Text('Hi')?

  1. Const widgets are drawn on the GPU while others use the CPU
  2. Const widgets can be changed later without calling setState
  3. Const widgets are required for the app to build in release
  4. Const widgets are created once and reused, saving rebuilds

Answer: D. Const widgets are created once and reused, saving rebuilds

Explanation

A const widget is canonicalised at compile time. Flutter can tell it has not changed and skip rebuilding that subtree.

Step-by-step solution

  1. Const widgets are created once during app startup.
  2. They are reused whenever needed, avoiding repeated creation.
  3. This reduces the number of rebuilds in the widget tree.
  4. Fewer rebuilds improve performance and efficiency.
  5. Thus, const widgets save resources by being created once and reused.
  6. Final answer: Const widgets are created once and reused, saving rebuilds.

Why the other options are wrong

  • A. Const widgets are not drawn on the GPU; they are reused objects, and the drawing path is the same.
  • B. A const widget still needs setState to change; const only means the object is fixed.
  • C. const is optional; the app builds in release without it, so it is not a requirement.

Tip: Use const for widgets that don't change to save memory and improve speed.

Question 5Medium

What does wrapping a frequently animating widget in RepaintBoundary do?

  1. Clips the widget so nothing outside its bounds is ever drawn
  2. Prevents the widget from ever being rebuilt by the framework
  3. Moves the widget's painting work to a separate isolate thread
  4. Gives it its own layer, so neighbours are not repainted

Answer: D. Gives it its own layer, so neighbours are not repainted

Explanation

A repaint boundary isolates painting: a spinner that repaints every frame no longer forces the static content around it to repaint.

Step-by-step solution

  1. RepaintBoundary creates a separate paint layer.
  2. A frequently repainting widget then repaints alone.
  3. Neighbouring widgets are not repainted.

Why the other options are wrong

  • A. Clipping is done by ClipRect, not RepaintBoundary.
  • B. It does not stop rebuilds, only repainting.
  • C. Painting is not moved to another isolate.

Tip: Animate inside a boundary.

Question 6Medium

To fade a widget in and out, why is FadeTransition or AnimatedOpacity preferred over rebuilding an Opacity widget every frame?

  1. AnimatedOpacity draws on the native platform view instead of Flutter
  2. Opacity widgets are removed in release mode, so the fade would vanish
  3. Opacity is only allowed on images, not on general widgets like Text
  4. They animate opacity efficiently without rebuilding the child every frame

Answer: D. They animate opacity efficiently without rebuilding the child every frame

Explanation

Rebuilding an Opacity in setState each tick rebuilds the subtree. The transition widgets update only the opacity of the render layer.

Step-by-step solution

  1. Rebuilding Opacity every frame triggers full widget rebuild.
  2. FadeTransition and AnimatedOpacity update opacity directly without full rebuild.
  3. Full rebuilds are slower and cause unnecessary layout recalculations.
  4. Animated widgets handle animations efficiently with minimal performance impact.
  5. They animate opacity changes smoothly without affecting other widget properties.
  6. Final answer: They animate opacity efficiently without rebuilding the child every frame.

Why the other options are wrong

  • A. AnimatedOpacity is a Flutter widget that animates in Flutter's own rendering, not a native platform view.
  • B. Opacity is not removed in release mode; it works the same in debug and release builds.
  • C. Opacity works on any widget, including Text, not only on images, so this limit is false.

Tip: Use AnimatedOpacity or FadeTransition for smooth, efficient opacity animations.

Question 7Medium

setState is called in a State near the root of the app to update one small badge. What is the performance problem?

  1. setState near the root is ignored, so the badge will never visibly update at all
  2. setState can only update the root widget, never any of its child widgets
  3. The whole subtree under that State rebuilds each time
  4. The badge is repainted twice, once for the root and once for the badge itself

Answer: C. The whole subtree under that State rebuilds each time

Explanation

setState rebuilds the State's entire build output. Moving the changing state lower, or using a listener just around the badge, limits the work.

Step-by-step solution

  1. Calling setState triggers a rebuild of the widget tree.
  2. The rebuild starts from the State where setState was called.
  3. Since the State is near the root, its entire subtree is affected.
  4. Every widget under that State is rebuilt, not just the badge.
  5. The performance problem is that the whole subtree under that State rebuilds each time.

Why the other options are wrong

  • A. Setting state near the root does not ignore the call, so the badge does update.
  • B. Any State's setState rebuilds its own subtree, which includes child widgets, so this limit is false.
  • D. The badge is not painted twice; the real cost is rebuilding every widget under that State.

Tip: Move stateful widgets as low in the tree as possible to minimize rebuild scope.

Question 8Medium

Why should you avoid sorting a large list or parsing JSON inside build?

  1. Work in build is skipped in release mode, so the result is missing
  2. Dart forbids calling list sort methods inside any widget's methods
  3. build can run very often, so the cost repeats each rebuild
  4. build runs on a background isolate where such work is not allowed

Answer: C. build can run very often, so the cost repeats each rebuild

Explanation

build should be cheap and side-effect free. Do expensive work once (initState, a model, or an isolate) and keep the result.

Step-by-step solution

  1. Build runs every time widget rebuilds, so repeated sorting or parsing adds cost.
  2. Large list sorting or JSON parsing takes time, which repeats on each rebuild.
  3. This slows app performance as build is called often during state changes.
  4. Expensive operations should be done once outside build, like in initState or a model.
  5. So the cost of sorting or parsing repeats each rebuild, making it inefficient.

Why the other options are wrong

  • A. Build work is not skipped in release mode, so the sorted or parsed result is still produced.
  • B. Dart does not forbid sorting or parsing in widget methods; it is allowed but can be slow.
  • D. build runs on the main UI thread, not a background isolate, so such work blocks the UI.

Tip: Move heavy work out of build to initState or a model for efficiency.

Question 9Hard

In AnimatedBuilder(animation: c, child: const Heavy(), builder: (ctx, child) => Transform.rotate(angle: c.value, child: child)), why pass Heavy as child?

  1. Heavy is built once and reused, while only the Transform rebuilds per tick
  2. The child parameter makes Heavy animate on a separate background isolate
  3. Passing it as child is required, or else AnimatedBuilder will throw an error
  4. It makes Heavy rotate in the opposite direction from the Transform widget

Answer: A. Heavy is built once and reused, while only the Transform rebuilds per tick

Explanation

The builder runs on every animation tick. The child argument is built once outside the builder, so only the cheap Transform wrapper is recreated.

Step-by-step solution

  1. Heavy is a widget that doesn't need to rebuild on every animation frame.
  2. Passing Heavy as child ensures it's built once and reused efficiently.
  3. Transform.rotate only rebuilds when the angle changes, saving resources.
  4. This setup avoids unnecessary rebuilding of Heavy on each animation tick.
  5. Only the Transform wrapper is recreated, making the animation smoother.
  6. Final answer: Heavy is built once and reused, while only the Transform rebuilds per tick.

Why the other options are wrong

  • B. The child parameter does not use an isolate; Heavy runs on the same main thread as everything else.
  • C. Heavy does not need to be a child; AnimatedBuilder works without a child, so no error is thrown.
  • D. Heavy is rotated by the same Transform in the same direction, since it is passed through as the child.

Tip: Use AnimatedBuilder to animate widgets efficiently by rebuilding only the transform wrapper.

Question 10Hard

A ListView with 5,000 items uses shrinkWrap: true inside a SingleChildScrollView. Why is this slow?

  1. shrinkWrap forces each item to be rebuilt on a separate isolate
  2. shrinkWrap turns off scrolling physics, so each frame is redrawn twice
  3. shrinkWrap must measure every item, which defeats lazy building
  4. shrinkWrap converts the list into images, which uses a lot of memory

Answer: C. shrinkWrap must measure every item, which defeats lazy building

Explanation

To size itself to its content, a shrink-wrapped list lays out all children. Prefer a CustomScrollView with slivers so items stay lazy.

Step-by-step solution

  1. ShrinkWrap: true tells the ListView to size itself to its content.
  2. To know the total size, the widget must measure every single item.
  3. Measuring all 5,000 items forces them to build immediately.
  4. This defeats the lazy building mechanism of the ListView.
  5. ShrinkWrap must measure every item, which defeats lazy building.

Why the other options are wrong

  • A. shrinkWrap does not move items to a separate isolate; the list still builds on the main thread.
  • B. shrinkWrap does not turn off scrolling physics; the slowdown comes from measuring all items.
  • D. shrinkWrap does not turn the list into images, so memory use is not the cause here.

Tip: Avoid shrinkWrap in long lists; use CustomScrollView with slivers for lazy loading.

Practise all 14 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all Flutter & Dart topics · All topics