Skip to content

fix(threads): avoid quadratic overlap check during resume hydration#586

Open
mhulden wants to merge 1 commit intoDimillian:mainfrom
mhulden:fix/thread-resume-overlap-linear
Open

fix(threads): avoid quadratic overlap check during resume hydration#586
mhulden wants to merge 1 commit intoDimillian:mainfrom
mhulden:fix/thread-resume-overlap-linear

Conversation

@mhulden
Copy link
Copy Markdown

@mhulden mhulden commented Mar 27, 2026

Summary

Long thread resume could become very slow because overlap detection in resume hydration used nested scans:

  • items.some(...) + localItems.some(...) (quadratic in combined list size)

This change replaces that with a Set of local item IDs and O(1) membership checks.

What changed

  • In buildResumeHydrationPlan (src/features/threads/utils/threadActionHelpers.ts):
    • build localItemIds = new Set(localItems.map(item => item.id))
    • replace nested overlap check with items.some(item => localItemIds.has(item.id))

Why

For long threads, this removes a hot O(n²) path during resume while keeping behavior identical.

Validation

  • npm run -s typecheck
  • npm run -s test -- src/features/threads/hooks/useThreadActions.test.tsx src/features/threads/hooks/useThreads.integration.test.tsx src/features/app/hooks/useRemoteThreadRefreshOnFocus.test.tsx src/utils/threadItems.test.ts
  • Built and tested aarch64 AppImage locally.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant