CardContentProvider: Avoid eager materialization of search results - #22290
david-allison wants to merge 6 commits into
Conversation
List the CardIds and return the current row of the cursor, rather than pre-fetching all rows. Reduces memory usage Part of 20253 Assisted-by: GPT-6
Part of 20253 Assisted-by: GPT-6
Only load when a column is read, so restoring the cursor position does not fetch an unused row. Part of 20253 Assisted-by: GPT-6
Defers rendering questions/answers/card names until they're requested. Part of 20253 Assisted-by: GPT-6
Part of 20253 Assisted-by: GPT-6
When loading a row, check if the card is deleted. If it is, all columns except the ID will return `null` Part of 20253 Assisted-by: GPT-6
| * For card searches, the matching card IDs and result count are fixed when the query runs. | ||
| * Other fields are loaded lazily and may reflect changes made while the cursor is open. | ||
| * If a card is deleted before its row is loaded, the row retains its [_ID] and returns `null` | ||
| * for all other requested columns. Rows already loaded may still contain the earlier values. |
There was a problem hiding this comment.
I suspect this won't be an issue due to consumer behavior, but it's a behavioural change
mikehardy
left a comment
There was a problem hiding this comment.
Hey David 👋
The search path was building a MatrixCursor of every matching Card (and rendering Q/A) before query() returned. LazyCursor holding the id list, loading one row on read, and letting CursorWindow bound peak memory is the #20253 plan. Eager findCards + column validation, _id-only fast path, and deleted-before-load rows keeping _id with nulls all look right, and the tests actually drive fillWindow / random access / the delete case.
On the self-thread: I think the CONTENT_URI KDoc is enough notice. I would not bump provider spec for this. Cross-process clients still get a window snapshot at fill time, and anyone iterating immediately never sees the live-reload edge. If a client holds the cursor across a collection mutation they can now see later values or nulls; that seems like the right trade for not OOMing large searches.
Thanks for keeping the other MatrixCursor sites out of this PR. LGTM
|
I want to wait for @mikehardy and @ankidroid/reviewers for this one Technically a breaking change in the API contract regarding concurrent updates and I'd like a few +1s to be sure I've not overlooked anything |
|
I saw the demote — fair call if you want another set of eyes on the live-cursor edge. From my side I am still +1 on the approach in the Approve: CONTENT_URI KDoc as the consumer notice, no provider.spec bump, and the trade for not OOMing large searches. Happy to leave this on Needs Second Approval until another reviewer lands. |
Note
Assisted-by: GPT-6
Purpose / Description
As discussed:
Fixes
Approach
Idremains, all other calls returnnullImportant
Please review the changed API semantics carefully
How Has This Been Tested?
Heavily tested
Checklist