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

Remove desugaring from this project #1485

Closed
wants to merge 3 commits into from

Conversation

Jaehwa-Noh
Copy link
Contributor

@Jaehwa-Noh Jaehwa-Noh commented May 31, 2024

What I have done and why

We can remove desugaring from this project.
The only usage of desugar API is just here.

@Composable
fun dateFormatted(publishDate: Instant): String = DateTimeFormatter
.ofLocalizedDate(FormatStyle.MEDIUM)
.withLocale(Locale.getDefault())
.withZone(LocalTimeZone.current.toJavaZoneId())
.format(publishDate.toJavaInstant())

When we remove the desugaring, we can remove androidDesugarJdkLibs dependency.
Output APK's size is reduced 1MB.
image

And there's no need to use JAVA 11 whether even use the desugaring, the JAVA version bumped at #1392 PR

Change-Id: I3738783395899cb1b96d09db2d97de36c530d5b7
- DateFormat
- getDateInstance
- DateFormat.MEDIUM

Change-Id: I2cfc4088101b816fed6260a6891439fc6dca20c3
Change-Id: I09037aac3333965db35913eaa48fb1f3e97c0edd
.format(publishDate.toJavaInstant())
fun dateFormatted(publishDate: Instant): String = DateFormat
.getDateInstance(DateFormat.MEDIUM, Locale.getDefault())
.format(publishDate.toEpochMilliseconds())

Choose a reason for hiding this comment

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

DateFormat is not thread-safe or immutable and DateTimeFormatter is.

ideally, the formatter would be remember'd (and thread-safe and immutable)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you to review it.
Let me says my opinion.

I checked the java documentation, it said

Synchronization

Date formats are not synchronized. It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally.

I don't think my DateFormat is called on multiple thread, it's only called on main thread.
And It has been created new DateFormat instance as NewsResourceCardExpanded is composed.

@alexvanyo
Copy link
Contributor

We use desugaring in a lot more places than just that one with our usage of kotlinx-datetime for time APIs on older SDK versions. This PR will crashes at startup on an API 21 device.

Using desugaring adds size to the APK (like any library), but for our minified release it is around 0.2 MB, which seems well worth it to be able to use much better time APIs.

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.

3 participants