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: On ui layer analytics injected by entrypoint #1472

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

rhkrwngud445
Copy link

@rhkrwngud445 rhkrwngud445 commented May 26, 2024

Issue: #1471

Suggest changing the UI layer injection method of Analytics Instance in Analytics Module.

Instead of using CompositionLocal, how about using Hilt's EntryPoint?

It has these advantages.

  1. It has the advantage of reducing MainActivity injection code.
  2. Management outside HiltScope can be reduced.
  3. Analytics can eliminate compose dependency.

Additionally, in analytics/AnalyticsModule, how about creating an instance as a singleton?

@@ -62,7 +62,7 @@ fun LazyStaggeredGridScope.newsFeed(
contentType = { "newsFeedItem" },
) { userNewsResource ->
val context = LocalContext.current
val analyticsHelper = LocalAnalyticsHelper.current
val analyticsHelper = analyticsInstance(context)
Copy link
Contributor

Choose a reason for hiding this comment

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

When the Composable is recomposed, accessing and retrieving from the Hilt dependency graph can incur costs. How about optimizing this by using remember? 🤔

Copy link
Author

@rhkrwngud445 rhkrwngud445 May 27, 2024

Choose a reason for hiding this comment

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

I agree that reducing cost
Thank you for your opinion!

commit

@yongsuk44
Copy link
Contributor

This is just a chat, but if a Composable that calls analyticsInstance() leaves the Composition and later AnalyticsHelper is needed again, it seems necessary to fetch the object from the dependency graph again. In the existing implementation, it is managed by the Activity Lifecycle, so I think there wouldn't be such unnecessary overhead. What do you think?

Additionally, according to the comments in the existing code, NoOpAnalyticsHelper() is used to run the Preview. Do you think the modified code can replace it?

@rhkrwngud445
Copy link
Author

rhkrwngud445 commented May 27, 2024

@yongsuk44 Thanks for your feedback

Additionally, according to the comments in the existing code, NoOpAnalyticsHelper() is used to run the Preview. Do you think the modified code can replace it?

I think it is changed by the lambda code so that preview will be OK

example commit

This is just a chat, but if a Composable that calls analyticsInstance() leaves the Composition and later AnalyticsHelper is needed again, it seems necessary to fetch the object from the dependency graph again. In the existing implementation, it is managed by the Activity Lifecycle, so I think there wouldn't be such unnecessary overhead. What do you think?

I also agree that cost existed.
It was confirmed that there was a difference of more than 5000 NanoTime. I think that it seems to be a trade-off area with the advantages I suggested.

@yongsuk44
Copy link
Contributor

  1. I think it would be simpler to write TrackScreenViewEvent in the InterestsRoute rather than hoisting. I'm curious if it's possible to replace the previews of components like userNewsResourceCardItems and newsFeed.

  2. It seems to me that comparing how much the frame changes through ScrollForYouFeedBenchmark would make things clearer. What do you think?

@rhkrwngud445
Copy link
Author

@yongsuk44
I think improvements can be made with a nested callback structure, but I don't think it's a good structure.

I suggested CompositionLocal because I was wondering why, and I found the answer.
Your suggestions and questions were helpful. Thank you.

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.

None yet

2 participants