Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use @Immutable, add ImmutableWrapper and ImmutableListWrapper to make @Composable functions skippable #664

Closed

Conversation

hoc081098
Copy link
Contributor

@hoc081098 hoc081098 commented Apr 15, 2023

  • Add @Immutable to Ui state classes.
  • Use ImmutableWrapper<T> instead of T when T is unstable (eg. domain model) in composable functions to make them skippable (ImmutableWrapper is @JvmInline value class -> no performance overhead).
  • Use ImmutableListWrapper<T> instead of List<T> when T is unstable (eg. domain model) in composable functions to make them skippable (ImmutableListWrapper is @JvmInline value class -> no performance overhead).
  • Use kotlinx.collections.immutable.ImmutableList<T>/kotlinx.collections.immutable.ImmutableSet<T> instead of List<T>/Set<T> when T is stable.

CURRENT

gradle app:assembleProdRelease -PenableComposeCompilerReports=true

BOOKMARKS

restartable scheme("[androidx.compose.ui.UiComposable]") fun BookmarksScreen(
  unstable feedState: NewsFeedUiState
  stable removeFromBookmarks: Function1<String, Unit>
  stable onTopicClick: Function1<String, Unit>
  stable modifier: Modifier? = @static Companion
)
restartable scheme("[androidx.compose.ui.UiComposable]") fun BookmarksGrid(
  unstable feedState: NewsFeedUiState
  stable removeFromBookmarks: Function1<String, Unit>
  stable onTopicClick: Function1<String, Unit>
  stable modifier: Modifier? = @static Companion
)

FOR YOU

restartable scheme("[androidx.compose.ui.UiComposable]") fun ForYouScreen(
  stable isSyncing: Boolean
  onboardingUiState: OnboardingUiState
  unstable feedState: NewsFeedUiState
  stable onTopicCheckedChanged: Function2<String, Boolean, Unit>
  stable onTopicClick: Function1<String, Unit>
  stable saveFollowedTopics: Function0<Unit>
  stable onNewsResourcesCheckedChanged: Function2<String, Boolean, Unit>
  stable modifier: Modifier? = @static Companion
)
restartable scheme("[androidx.compose.ui.UiComposable]") fun TopicSelection(
  unstable onboardingUiState: Shown
  stable onTopicCheckedChanged: Function2<String, Boolean, Unit>
  stable modifier: Modifier? = @static Companion
)

INTERESTS

restartable scheme("[androidx.compose.ui.UiComposable]") fun TopicsTabContent(
  unstable topics: List<FollowableTopic>
  stable onTopicClick: Function1<String, Unit>
  stable onFollowButtonClick: Function2<String, Boolean, Unit>
  stable modifier: Modifier? = @static Companion
)

TOPIC

restartable scheme("[androidx.compose.ui.UiComposable]") fun TopicToolbar(
  unstable uiState: FollowableTopic
  stable modifier: Modifier? = @static Companion
  stable onBackClick: Function0<Unit>? = @static {

}

APP

restartable scheme("[androidx.compose.ui.UiComposable]") fun NiaApp(
  stable windowSizeClass: WindowSizeClass
  unstable networkMonitor: NetworkMonitor
  stable appState: NiaAppState? = @dynamic rememberNiaAppState(windowSizeClass, networkMonitor, null, null, $composer, 0b01000000 or 0b1110 and $dirty, 0b1100)
)
restartable scheme("[androidx.compose.ui.UiComposable]") fun NiaNavRail(
  unstable destinations: List<TopLevelDestination>
  stable onNavigateToDestination: Function1<TopLevelDestination, Unit>
  unstable currentDestination: NavDestination?
  stable modifier: Modifier? = @static Companion
)
restartable scheme("[androidx.compose.ui.UiComposable]") fun NiaBottomBar(
  unstable destinations: List<TopLevelDestination>
  stable onNavigateToDestination: Function1<TopLevelDestination, Unit>
  unstable currentDestination: NavDestination?
  stable modifier: Modifier? = @static Companion
)

CORE UI

restartable scheme("[androidx.compose.ui.UiComposable]") fun NewsResourceCardExpanded(
  unstable userNewsResource: UserNewsResource
  stable isBookmarked: Boolean
  stable onToggleBookmark: Function0<Unit>
  stable onClick: Function0<Unit>
  stable onTopicClick: Function1<String, Unit>
  stable modifier: Modifier? = @static Companion
)
restartable scheme("[androidx.compose.ui.UiComposable]") fun NewsResourceMetaData(
  unstable publishDate: Instant
  stable resourceType: NewsResourceType
)
restartable scheme("[androidx.compose.ui.UiComposable]") fun NewsResourceTopics(
  unstable topics: List<FollowableTopic>
  stable onTopicClick: Function1<String, Unit>
  stable modifier: Modifier? = @static Companion
)

AFTER

There are some unskippable functions left: NiaApp, NiaNavRail, NiaBottomBar

@hoc081098 hoc081098 changed the title refactor: use @Immutable, add ImmutableWrapper and ImmutableListWrapper to make @Composable functions skippable refactor: use @Immutable, add ImmutableWrapper and ImmutableListWrapper to make @Composable functions skippable Apr 15, 2023
@dungngminh
Copy link

Nice 🤤

Copy link
Contributor

@mmoczkowski mmoczkowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, but I'm not sure I like the increased complexity and decreased readability. Let's ask the compose expert. @simona-anomis would you be so kind and check this PR?

@astamato astamato requested a review from bentrengrove May 4, 2023 13:20
Copy link
Member

@bentrengrove bentrengrove left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution and effort. Unfortunately, we can't merge a large PR like this. To land a performance change like this you would need to show the changes actually improved performance and were worth the increase in code complexity. You can see an example of this here, #380

You would also need to split the PR up into smaller changes with an accompanied benchmark test for each change showing the before and after performance change please.

@mmoczkowski
Copy link
Contributor

Thank you for your hard work. As Ben says, we can't merge it as is, but you can still create smaller PRs with documented performance improvements.

@mmoczkowski mmoczkowski closed this May 5, 2023
@hoc081098 hoc081098 mentioned this pull request Oct 10, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants