FrequentlyChangingValue


FrequentlyChangingValue is used to denote properties and functions that return values that change frequently during runtime, and cause recompositions when they are read (for example, if they are backed with snapshot state). Reading these values in composition can cause performance issues due to frequent recompositions - for example reading a list's scroll position. An associated lint check will warn for reads of annotated properties and functions inside composition.

To avoid frequent recompositions, instead consider:

  • Using derivedStateOf to filter state changes based on a provided calculation. For example, rather than recomposing on every scroll position change, only recomposing if the scroll position changes from 0 (at the top of the list) to greater than 0 (not at the top of the list), and vice versa.

  • Using snapshotFlow to create a flow of changes from a provided state. This can then be collected inside a LaunchedEffect, and used to make changes without needing to recompose.

  • When using Compose UI, read this value inside measure / layout / draw, depending on where it is needed. This will cause invalidation of the corresponding phase, instead of a recomposition. See developer.android.com for more information on Jetpack Compose phases.

Summary

Public constructors

Cmn

Public constructors

FrequentlyChangingValue

FrequentlyChangingValue()