Contact search blocks the UI with a large address book
Checklist
- [x] I can reproduce the bug with the latest version given here.
- [x] I made sure that there are no existing issues - open or closed - to which I could contribute my information.
- [x] I made sure that there are no existing discussions - open or closed - to which I could contribute my information.
- [x] I have read the FAQs inside the app (Menu -> About -> FAQs) and my problem isn't listed.
- [x] I have taken the time to fill in all the required details. I understand that the bug report will be dismissed otherwise.
- [x] This issue contains only one bug.
- [x] I have read and understood the contribution guidelines.
Affected app version
1.11.1
Affected Android/Custom ROM version
Android 10
Affected device model
Huawei LYA-L29
How did you install the app?
F-Droid / IzzyOnDroid
Steps to reproduce the bug
- Use an address book with several thousand contacts (3,520 contacts containing phone numbers in my test).
- Open the Contacts tab and activate search.
- Type and delete queries of 1 to 7 characters.
- Observe UI stalls while typing.
Expected behavior
Typing and deleting a query should remain responsive with a large address book in a fast way not delaying...
Actual behavior
Contact filtering and repeated normalization run on the main thread for each keystroke, causing visible stalls.
Screenshots/Screen recordings
Not attached. Timing measurements are included below.
Additional information
I have a working version with a fix, tested on the same phone and address book. I reproduced the original problem and verified the improvement on the device. Search feels substantially faster and more responsive in everyday use.
| Measurement | Before | Working version |
|---|---|---|
| Main-thread work per keystroke | 70 to 185 ms | 2 to 31 ms, typically 3 to 6 ms |
| Filtering | On the main thread | 7 to 30 ms on a background thread |
The first keystroke in the baseline took 437 ms. The measurements used temporary SystemClock.elapsedRealtime() instrumentation around the search handler, with roughly 60 keystrokes of typing and deleting queries. These are single-device results, and main-thread time is not the same as end-to-end result latency.
ContactsFragment.onSearchQueryChanged() repeatedly normalizes up to six fields per contact on every keystroke. My patch precomputes searchable text once per contact list, performs filtering on a background thread, and discards outdated results when the query changes or search closes. It preserves the existing matching and ordering rules, including accent-insensitive and numeric searches, which I have tested on the device.
This concerns typing in the Contacts tab, rather than initial contact loading or search in the dial pad/call history.
I'd like to contribute this as a focused PR. Your contribution guidelines require the help wanted label before submission. Could a maintainer add it so I can open the PR?