Skip to content

Conversation

kean
Copy link
Contributor

@kean kean commented Sep 12, 2025

Fixes https://linear.app/a8c/issue/CMM-93/ipad-search-function-freezing-in-reader. Search is now performed in the background and in parallel. It would be nice to optimize search itself, but I didn't get to it. It's OK for most use-cases.

@kean kean added this to the 26.4 milestone Sep 12, 2025
@kean kean requested a review from crazytonyli September 12, 2025 14:54
@kean kean added the Reader label Sep 12, 2025
@kean kean force-pushed the fix/subscription-search-performance branch from f1dda0f to 3354a73 Compare September 12, 2025 14:54
@dangermattic
Copy link
Collaborator

1 Warning
⚠️ View files have been modified, but no screenshot or video is included in the pull request. Consider adding some for clarity.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Sep 12, 2025

App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number29144
VersionPR #24841
Bundle IDorg.wordpress.alpha
Commit4d52aa1
Installation URL036kog98dnnd8
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Sep 12, 2025

App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number29144
VersionPR #24841
Bundle IDcom.jetpack.alpha
Commit4d52aa1
Installation URL25joq5gd5ueso
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

// If there's a pending search, start it now
if let pendingSearchText {
performBackgroundSearch(searchText: pendingSearchText)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the use of pendingSearchText is a bit confusing. Every change to the search input would trigger a performBackgroundSearch call, which would perform a new search. That makes me think if this call here is redundant?

Copy link
Contributor Author

@kean kean Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was late and I failed to fully check the implementation. It does seems like it included parts of two separate strategies in one. I rewrote it manually.

let searchableData = subscriptions.map(SearchableSubscription.init)

// Perform the search on a background queue with parallel processing
let resultObjectIDs = await StringRankedSearch(searchTerm: currentSearchText)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe check cancellation before the await call, just in case performBackgroundSearch gets called too frequently?

@kean kean requested a review from crazytonyli September 19, 2025 15:57
@kean kean enabled auto-merge September 19, 2025 18:11
let items = Array(items)

// Calculate optimal chunk size based on CPU cores (leave one core free)
let maxConcurrency = max(1, ProcessInfo.processInfo.activeProcessorCount - 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a request to change, but I'm curious if controlling the number of Task instances in the TaskGroup is necessary.

Let's say you create one Task for each element, that does not necessarily mean TaskGroup will run them simultaneously on the same number of threads. I'd be surprised if Swift actually does that. I'd expect TaskGroup, or Swift concurrency in general, to schedule Task appropriately according to the number of CPU cores, or whatever metric they see appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swift concurrency will limit the number of tasks to the number of available cores. The app still needs to create chunks as submitting one at a time would likely be wasteful – more time will be spent on dispatching work than performing it. I think a better option would probably be to create more chunk – not too large not too small.

.parallelSearch(in: searchableData) { $0.searchableText }
.map(\.objectID)

searchResults = subscriptions.filter { resultObjectIDs.contains($0.objectID) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert resultObjectIDs to a Set before filter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right forgot to do it – fixed.

@kean kean force-pushed the fix/subscription-search-performance branch from cbd106a to 5ffd81e Compare September 22, 2025 22:25
Copy link

@kean kean added this pull request to the merge queue Sep 22, 2025
Merged via the queue into trunk with commit ae0876e Sep 22, 2025
30 of 32 checks passed
@kean kean deleted the fix/subscription-search-performance branch September 22, 2025 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants