Skip to content

[$175] Performance: Cap cached Search snapshots at 25 using LRU eviction #106780

Open

Description

@melvin-bot

Problem

Distinct Search queries persist separate snapshots in Onyx/IndexedDB across sessions. Quota-triggered eviction allows these to accumulate on web, duplicating large policy payloads and increasing storage and update work.

Proposed change

  • Keep at most 25 ordinary cached Search snapshots, evicting the least recently used.
  • Preserve snapshots for current, saved, and suggested searches outside that cap.
  • Prune existing oversized caches, not just newly created snapshots.
  • Remove evicted snapshots from both memory and persistent storage.

Acceptance criteria

  • Running more than 25 distinct queries evicts the least recently used eligible snapshots.
  • Revisiting a cached query refreshes its recency.
  • Evicted queries refetch correctly when reopened.
  • Current, saved, and suggested searches remain functional.
  • The cap remains enforced across app restarts.

Related: #99415
Slack discussion

Issue OwnerCurrent Issue Owner: @FitseTLT
Upwork Automation - Do Not Edit

Activity

  1. added theissue type on Nov 12, 2026
  2. added
    Reviewing
    Weekly
    and removed
    Daily
    on Nov 13, 2026
  3. self-assigned this
    on Nov 13, 2026
  4. added
    Daily
    Bug
    and removed
    Weekly
    on Dec 1, 2026
  5. added
    External
    on Dec 1, 2026
  6. expensify-chore-bot commented on Dec 1, 2026

    @expensify-chore-bot

    Current assignee @FitseTLT is eligible for the External assigner, not assigning anyone new.

  7. changed the title [-]Performance: Cap cached Search snapshots at 25 using LRU eviction[/-] [+][$175] Performance: Cap cached Search snapshots at 25 using LRU eviction[/+] on Dec 1, 2026
  8. expensify-chore-bot commented on Dec 1, 2026

    @expensify-chore-bot
  9. MelvinBot commented on Dec 1, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    Search creates a persistent snapshot for each distinct query hash, but there is no application-level snapshot count limit. Snapshots are eligible for storage-pressure eviction; that does not enforce a 25-entry cache.

    Confidence: Medium — supported by code inspection; browser persistence and performance were not independently tested.

    Supporting evidence

    This explains accumulation across sessions. It does not independently establish the magnitude of the storage or performance impact.

    What changes do you think we should make in order to solve the problem?

    Continue the existing fix: Cap cached Search snapshots at 25 with LRU eviction, rather than opening a duplicate implementation.

    The policy should:

    • Persist query-access order and refresh it on cached revisits, not just requests.
    • Keep the newest 25 ordinary snapshots, with current/saved/suggested snapshots excluded from that budget.
    • Reconcile existing snapshots at startup and whenever protection changes.
    • Delete complete evicted keys from memory and persistent storage.
    • Re-enforce the limit after delayed responses recreate snapshots.

    The existing PR needs three acceptance-criteria decisions/corrections:

    Existing implementation gaps
    1. Saved/suggested protection has its own cap. The PR can evict unmounted pinned snapshots beyond a separate 25-entry budget—even when they still represent valid saved searches. That conflicts with the issue’s stated exemption. See SearchSnapshotCache.ts:23–30.

    2. Legacy migration clears every snapshot. This includes cached current/saved/suggested results. Online refetch can restore them, but offline availability is lost. Preserve protected entries during reconciliation, or explicitly approve this one-time exception. See ClearUntrackedSearchSnapshots.ts:11–18.

    3. Removing active protection does not trigger pruning. Closing a protected consumer can leave more than 25 ordinary snapshots until subsequent cache activity. Schedule reconciliation when protection is removed. See SearchSnapshotCache.ts:86–101.

    Validation: Cover 26+ ordinary queries, cached revisits, 26+ saved searches, oversized-cache startup, reload persistence, offline preservation, unmount-triggered pruning, and delayed-response recreation. Verify deletion in both Onyx and IndexedDB, then reopen an evicted query online.

    What alternative solutions did you explore? (Optional)

    Quota-only eviction does not enforce the requested limit. Request-only pruning also misses cached accesses and startup reconciliation; a blanket cache reset sacrifices protected offline results.


    Next Steps for Contributor+ team:
    To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/106780) to create a draft PR.
    To refine: @MelvinBot <your feedback>
    To reject: Explain why you are rejecting Melvin's proposal.


    view run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugDailyExternalReviewingTask

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions