You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In current implementation of NiaApp, we've observed an issue where unrelated state changes, such as modifications to showSettingsDialog, trigger unnecessary recompositions across the entire app, including within NiaNavHost and its child screens
Upon investigation, we identified that lambda expressions, such as onTopicClick, are being recreated with each recomposition cycle. Compose treats these newly instantiated lambda expressions as different from their predecessors, thus triggering recompositions even when there are no pertinent state changes.
this behavior will persist until the Jetpack Compose Compiler is updated to version 1.7, which is expected to introduce an enhanced 'Strong skipping' mode for more efficient recomposition skipping. In the meantime, developers are advised to manage lambda instances manually using remember to mitigate unnecessary recompositions.
This is particularly evident in screens like ForYouScreen, where the onTopicClick lambda is passed down and utilized. Despite showSettingsDialog having no direct relation to these screens, they undergo recomposition, leading to performance inefficiencies.
Describe the solution
I propose to mitigate this issue by employing the remember construct to cache navigation-related lambda expressions within NiaNavHost. This approach will ensure that lambdas are only recreated when genuinely necessary, such as when the NavController instance changes
change
before
after
Additional context
No response
Code of Conduct
I agree to follow this project's Code of Conduct
The text was updated successfully, but these errors were encountered:
This was a great investigation and your conclusion is correct! We will be enabling strong skipping mode in this project very soon so it isn't worth implementing the fix to manually remember lambdas. It would actually introduce a small amount of tech debt as the remember would become redundant once strong skipping is enabled.
I'll close this issue out but thank you for the report.
Is there an existing issue for this?
Describe the problem
In current implementation of NiaApp, we've observed an issue where unrelated state changes, such as modifications to showSettingsDialog, trigger unnecessary recompositions across the entire app, including within NiaNavHost and its child screens
Upon investigation, we identified that lambda expressions, such as onTopicClick, are being recreated with each recomposition cycle. Compose treats these newly instantiated lambda expressions as different from their predecessors, thus triggering recompositions even when there are no pertinent state changes.
this behavior will persist until the Jetpack Compose Compiler is updated to version 1.7, which is expected to introduce an enhanced 'Strong skipping' mode for more efficient recomposition skipping. In the meantime, developers are advised to manage lambda instances manually using remember to mitigate unnecessary recompositions.
This is particularly evident in screens like ForYouScreen, where the onTopicClick lambda is passed down and utilized. Despite showSettingsDialog having no direct relation to these screens, they undergo recomposition, leading to performance inefficiencies.
Describe the solution
I propose to mitigate this issue by employing the
remember
construct to cache navigation-related lambda expressions withinNiaNavHost
. This approach will ensure that lambdas are only recreated when genuinely necessary, such as when theNavController
instance changeschange
before
after
Additional context
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: