1 /* 2 * Copyright 2025 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.compose.runtime.annotation 18 19 /** 20 * FrequentlyChangingValue is used to denote properties and functions that return values that change 21 * frequently during runtime, and cause recompositions when they are read (for example, if they are 22 * backed with snapshot state). Reading these values in composition can cause performance issues due 23 * to frequent recompositions - for example reading a list's scroll position. An associated lint 24 * check will warn for reads of annotated properties and functions inside composition. 25 * 26 * To avoid frequent recompositions, instead consider: 27 * - Using derivedStateOf to filter state changes based on a provided calculation. For example, 28 * rather than recomposing on every scroll position change, only recomposing if the scroll 29 * position changes from 0 (at the top of the list) to greater than 0 (not at the top of the 30 * list), and vice versa. 31 * - Using snapshotFlow to create a flow of changes from a provided state. This can then be 32 * collected inside a LaunchedEffect, and used to make changes without needing to recompose. 33 * - When using Compose UI, read this value inside measure / layout / draw, depending on where it is 34 * needed. This will cause invalidation of the corresponding phase, instead of a recomposition. 35 * See developer.android.com for more information on Jetpack Compose phases. 36 */ 37 @MustBeDocumented 38 @Target(AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER) 39 @Retention(AnnotationRetention.BINARY) 40 public annotation class FrequentlyChangingValue 41