Skip to content
tezvyn:

Implement an efficient list in Jetpack Compose

Source: developer.android.comMediumHow cards are made

Implement an efficient list in Jetpack Compose

Tests your grasp of UI virtualization in Compose. Answer: Use LazyColumn as it only composes visible items. Contrast this with Column, which composes all items at once, causing poor performance. Mention the items DSL.

What's really being asked

This question assesses your understanding of UI virtualization and performance in Compose. The interviewer wants to see if you know the fundamental difference between composing all elements versus composing only what's visible. It separates candidates who just know the syntax from those who understand the performance implications of their UI code.

The full answer

A strong answer has four key parts. First, state clearly that LazyColumn (or LazyRow) is the correct tool. Second, explain why: LazyColumn virtualizes its content, meaning it only composes and measures the items that are currently visible (or about to be visible) on screen. Third, contrast this directly with a Column containing a forEach loop. A Column composes its entire content upfront, which for a list of 1,000 items would mean creating 1,000 composables at once, leading to long frame times and high memory usage. Fourth, briefly mention the LazyListScope DSL, specifically the items function for handling lists of data.

The mistakes people make

The most common mistake is suggesting a Column with the verticalScroll modifier. This makes the content scrollable but does not provide virtualization; all items are still composed at once, which is the core performance problem. Another red flag is being unable to explain the "why" behind LazyColumn. Simply saying "use LazyColumn" without explaining virtualization shows a surface-level understanding. Finally, incorrectly applying RecyclerView terminology like ViewHolder recycling directly to Compose can be a flag; while the goal is similar, Compose achieves it through intelligent recomposition, not by recycling view objects.

What usually comes next

Expect questions about more advanced LazyList features. "How would you implement a sticky header?" (Answer: stickyHeader within the LazyListScope). "How would you handle different item types in the same list?" (Answer: Use multiple item or items calls, or a when statement inside a single items block based on item type). "How can you optimize item recomposition?" (Answer: Ensure the data class for your items is stable and use the key parameter in the items function to help Compose track items across data changes).

A concrete example

For a list of 1,000 strings, a Column might take 200-300ms to compose initially, causing a noticeable UI freeze. A LazyColumn displaying the same list would compose in under 16ms, as it only renders the ~10-15 items visible on screen. The performance difference is not linear; it gets exponentially worse for the Column as the list size grows.

Interview question

To display a list of 1,000 items efficiently in Jetpack Compose, which approach best prevents UI freezes and high memory usage?

  • a.Using a Column composable with a verticalScroll modifier.
  • b.Implementing a LazyColumn with the items DSL.Correct
  • c.Creating a custom RecyclerView wrapper for Android View interoperability.
  • d.Wrapping a Column in a ScrollableContainer and optimizing item remember calls.
Why?

LazyColumn virtualizes its content, meaning it only composes and measures items that are currently visible, ensuring optimal performance for large lists. A Column with a verticalScroll modifier makes content scrollable but still composes all items at once, leading to performance issues.

Just read this? Test yourself on what you have been reading.

Read the original → developer.android.com

You just looked this up. Could you explain it out loud?

That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on android — each one lists the topics its interview covers.

See open roles