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

Optimize Query and BroadQuery when not including data fields #249

Closed
3 tasks done
vestrel00 opened this issue Aug 1, 2022 · 2 comments
Closed
3 tasks done

Optimize Query and BroadQuery when not including data fields #249

vestrel00 opened this issue Aug 1, 2022 · 2 comments
Assignees
Labels
performance Improvements to memory and/or cpu usage

Comments

@vestrel00
Copy link
Owner

vestrel00 commented Aug 1, 2022

The documentation I put up for optimizing queries by using include is currently not implemented (I thought I already did though!!!).

Screen Shot 2022-08-01 at 6 57 15 AM

Problem

When using the Query or BroadQuery APIs, the data table is still queried even if no data field is included.

// Collect Data for non-blank RawContact and Contact in the given offsetAndLimitedContactIds.
// If offsetAndLimitedContactIds is null, then all Data and non-blank RawContacts and Contacts
// are collected.
query(
Table.Data, include, offsetAndLimitedContactIds?.let {
Fields.Contact.Id `in` it
},
processCursor = contactsMapper::processDataCursor
)

This is a completely unnecessary query if only Fields.Contact fields are included. It leads to unnecessary parsing of potentially large number of data rows.

Only the Contacts and RawContacts table need to be queried. The Data table can be skipped in such cases.

Solution

Skip the data query if no data field is included.

  • Update https://vestrel00.github.io/contacts-android/entities/include-only-desired-data/#optimizing-queries by mentioning that the optimization is available sine v0.2.4. Also update the benchmark numbers (10,000 contacts currently takes 1-2 seconds but it could be reduced by 50%+ with this optimization!)
  • Add a note that not including any data fields will result in all returned Contact and RawContact entities to be blank (isBlank will return true) even if they are actually not blank in the database.
  • Update gh-pages branch
@vestrel00 vestrel00 added the performance Improvements to memory and/or cpu usage label Aug 1, 2022
@vestrel00 vestrel00 self-assigned this Aug 1, 2022
@vestrel00 vestrel00 added this to In progress in General maintenance Aug 1, 2022
@vestrel00 vestrel00 pinned this issue Aug 1, 2022
@vestrel00 vestrel00 moved this from In progress to Done in General maintenance Aug 2, 2022
@vestrel00
Copy link
Owner Author

vestrel00 commented Aug 2, 2022

Queries that only include fields from Fields.Contact are now 10x faster (varies depending on data set size)!!!!

@vestrel00 vestrel00 unpinned this issue Aug 5, 2022
@vestrel00
Copy link
Owner Author

This is included in 0.2.4!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Improvements to memory and/or cpu usage
Projects
Development

No branches or pull requests

1 participant