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

Import is slow #143

Open
7 tasks done
tom93 opened this issue Mar 22, 2024 · 0 comments
Open
7 tasks done

Import is slow #143

tom93 opened this issue Mar 22, 2024 · 0 comments
Labels
enhancement New feature or request needs triage Issue is not yet ready for PR authors to take up

Comments

@tom93
Copy link
Contributor

tom93 commented Mar 22, 2024

Checklist

  • I can reproduce the bug with the latest version given here.
  • I made sure that there are no existing issues - open or closed - to which I could contribute my information.
  • I made sure that there are no existing discussions - open or closed - to which I could contribute my information.
  • I have read the FAQs inside the app (Menu -> About -> FAQs) and my problem isn't listed.
  • I have taken the time to fill in all the required details. I understand that the bug report will be dismissed otherwise.
  • This issue contains only one bug.
  • I have read and understood the contribution guidelines.

Affected app version

1.0.1

Affected Android/Custom ROM version

Android 8.1, Android 14

Affected device model

Moto G5 Plus, emulator

How did you install the app?

Built from source

Steps to reproduce the bug

Import a .json backup with thousands of messages (example with 3000 messages, generated using the code at the end).

Expected behavior

The import should either complete quickly or display proper progress indication (for example as a notification). Related: #120 (request for progress dialogs across all apps).

Actual behavior

There is a toast saying "Importing...", and then it disappears and it seems like nothing is happening. A long time later (possibly several minutes) there is a toast saying "Importing successful". This is unacceptable, because the user has no idea what's going on (whether the import is still running or whether it crashed).

Screenshots/Screen recordings

No response

Attempt to make import faster using bulkInsert()

I tried making the import faster by switching from ContentProvider.insert() to ContentProvider.bulkInsert() as well as some other improvements (branch "import-bulk", commit), however that doesn't help that much. It reduces the time by 36% on Android 8.1 (66 sec => 42 sec) and 60% on Android 14 (72 sec => 26 sec) in an emulator with the attached 3000-message example (tested using this commit, which adds debug toasts and logcat messages to allow calculating the duration from the timestamps). The patched version is super fast on messages that already exist, but that doesn't help during the initial import. I'm not sure if it's worth merging, because it's a little complicated for not-very-big gains and the error handling isn't great (if one message in a chunk fails, then the rest of the chunk is skipped).

I don't think we can make the import any faster than that, because almost all of the time is spent in the bulkInsert() call waiting for the Telephony provider, which is outside of our control. We'd have to file a bug report against Android and hope that Google makes the code faster.

So I guess we have to show a proper progress indicator (e.g. using a notification; or at the bare minimum show multiple toasts).

Prior art

It might be worth comparing to the SMS Import / Export app to check if they have any tricks to speed up the import (based on a quick skim it doesn't appear so, but I think it's still worth doing a quick benchmark).

Testing code

For testing, the following Python code can be used to generate a large backup:

print("[")
for i in range(3000):
    print('%s{"subscriptionId":1,"address":"6505550","body":"Message %d","date":%d,"dateSent":0,"locked":0,"protocol":null,"read":1,"status":-1,"type":%d,"serviceCenter":null,"backupType":"sms"}' %
          ("," if i != 0 else "", i + 1, 1700000000000 + i * 60*1000, i % 2 + 1))
print("]")

Credit

Originally reported by @Abcd1234-dot in #88 (comment).

@tom93 tom93 added bug Something is not working needs triage Issue is not yet ready for PR authors to take up labels Mar 22, 2024
@Aga-C Aga-C added enhancement New feature or request and removed bug Something is not working labels Mar 22, 2024
@tom93 tom93 mentioned this issue Mar 25, 2024
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs triage Issue is not yet ready for PR authors to take up
Projects
None yet
Development

No branches or pull requests

2 participants