Knowledgebase

Compose Performance Print

  • mobiledevelopment, mobile, performance, guide, howto, solution, zillionkinghost, hosting
  • 0

Avoiding unnecessary recomposition.

WHAT CAUSES POOR PERFORMANCE

Recomposing more than necessary Expensive work during composition Reading state at too high a level Unstable parameters

WHAT UNSTABLE MEANS

A type Compose cannot determine is unchanged, so it assumes it changed.

WHAT CAUSES IT

Mutable collections Types from modules Compose cannot analyse Lambdas capturing changing values

WHAT TO PREFER

Immutable data Stable collection types

WHAT READING STATE AT TOO HIGH A LEVEL CAUSES

A large portion of the interface recomposing when a small part changed.

WHAT TO DO ABOUT IT

Read the state as close as possible to where it is used, by passing a function rather than a value where appropriate.

WHAT TO MEASURE WITH

The layout inspector and recomposition counts.

WHY MEASURE

Guessing about recomposition is unreliable.

WHAT TO AVOID

Optimising before measuring Heavy computation during composition

WHAT TO MOVE

Computation into remembered values, or into the view model.

WHAT TO TEST ON

A modest device, where the cost is visible.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot