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: remove old date time parser APIs (WPB-9934) #3171

Merged
merged 37 commits into from
Jul 12, 2024

Conversation

yamilmedina
Copy link
Contributor

@yamilmedina yamilmedina commented Jul 8, 2024

TaskWPB-9934 [Android] Replace SimpleDateFormat for modern APIs DateTimeFormatter or Instant


PR Submission Checklist for internal contributors

  • The PR Title

    • conforms to the style of semantic commits messages¹ supported in Wire's Github Workflow²
    • contains a reference JIRA issue number like SQPIT-764
    • answers the question: If merged, this PR will: ... ³
  • The PR Description

    • is free of optional paragraphs and you have filled the relevant parts to the best of your ability

What's new in this PR?

Issues

Currently, the application has an excessive use of SimpleDateFormat in reloaded, this is mainly used for formatting dates in messages (conversation screen), devices, read receipts, to name a few.

Causes (Optional)

  • Not Thread Safe.
  • Creating instances is CPU intensive.
  • Time Zones can mutate for instances.
  • Slower performance according to benchmarks in devices, this translates ie, into increased battery consumption.

Solutions

Upgrade to newer APIs, replacing:

  • SimpleDateFormat for DateTimeFormatter
  • java.text apis for java.time apis
  • Deprecate old extensions functions formatters, but keep it to compare perf. we can remove later.
  • Added instrumented tests for the old APIs vs new, to compare.

Some samples running in an emulator for 10_000_000 conversions has the following results.

Formatter Time taken
SimpleDateFormat 2m 3.602497059s
DateTimeFormat 53.214024317s
Instant 53.528359068s

Testing

Test Coverage (Optional)

  • I have added automated test to this contribution

PR Post Submission Checklist for internal contributors (Optional)

  • Wire's Github Workflow has automatically linked the PR to a JIRA issue

PR Post Merge Checklist for internal contributors

  • If any soft of configuration variable was introduced by this PR, it has been added to the relevant documents and the CI jobs have been updated.

References
  1. https://sparkbox.com/foundry/semantic_commit_messages
  2. https://github.com/wireapp/.github#usage
  3. E.g. feat(conversation-list): Sort conversations by most emojis in the title #SQPIT-764.

@yamilmedina yamilmedina added WIP Work In Progress DO NOT MERGE labels Jul 8, 2024
@yamilmedina yamilmedina changed the title feat: remove old date time parser APIs (WPB-9934) refactor: remove old date time parser APIs (WPB-9934) Jul 8, 2024
Copy link
Contributor

github-actions bot commented Jul 9, 2024

Built wire-android-staging-compat-pr-3171.apk is available for download

Copy link
Contributor

github-actions bot commented Jul 9, 2024

Built wire-android-dev-debug-pr-3171.apk is available for download

Copy link
Member

@vitorhugods vitorhugods left a comment

Choose a reason for hiding this comment

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

Nicely done.

Just a couple of small adjustments to make sure the test works in all machines, and further encourage dropping of String for internal date representation.

About dropping String, take the Device class for example. It has a registrationTime, which we transform from Instant to String.
And then we format this String again in order to show it in the UI.

There are multiple places where we do this and we should drop it. Keep Instant all the way through until it's time to display in the UI.

Copy link
Contributor

github-actions bot commented Jul 9, 2024

Built wire-android-staging-compat-pr-3171.apk is available for download

Copy link
Contributor

github-actions bot commented Jul 9, 2024

Built wire-android-dev-debug-pr-3171.apk is available for download

Copy link
Member

@MohamadJaara MohamadJaara left a comment

Choose a reason for hiding this comment

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

Great work as always 🔥

@yamilmedina yamilmedina removed WIP Work In Progress DO NOT MERGE labels Jul 12, 2024
Copy link

sonarcloud bot commented Jul 12, 2024

@yamilmedina yamilmedina added this pull request to the merge queue Jul 12, 2024
Copy link
Contributor

Built wire-android-staging-compat-pr-3171.apk is available for download

Copy link
Contributor

Built wire-android-dev-debug-pr-3171.apk is available for download

Merged via the queue into develop with commit 3a803c8 Jul 12, 2024
10 of 11 checks passed
@yamilmedina yamilmedina deleted the feat/remove-oldapi-simpledateformat branch July 12, 2024 09:47
@echoes-hq echoes-hq bot added the echoes: maintenance Maintenance activity - Refactoring , Preventive , Improvements to code , Performance improvements label Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
echoes: maintenance Maintenance activity - Refactoring , Preventive , Improvements to code , Performance improvements size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants