Optimizing the search faster; don't trigger full re render by URL changes.

This commit is contained in:
2026-01-31 22:17:05 +00:00
parent bc355d991d
commit f94ccc01c6
5 changed files with 48 additions and 27 deletions
+6 -4
View File
@@ -75,8 +75,9 @@ function yieldControl(): Promise<void> {
async function performSearch(query: string, loc: string, searchId: number) {
const needle = needleFormat(query)
const limit = 100
const batchSize = 1000
const batchSize = 500 // Smaller batches for faster incremental feedback
const results: WorkerDoc[] = []
let lastResultCount = 0
for (let i = 0; i < recentDocuments.length && results.length < limit; i += batchSize) {
// Check if search was superseded
@@ -91,8 +92,9 @@ async function performSearch(query: string, loc: string, searchId: number) {
}
}
// Post incremental results if we found any in this batch
if (results.length > 0 && currentSearchId === searchId) {
// Post incremental results if we found new matches
if (results.length > lastResultCount && currentSearchId === searchId) {
lastResultCount = results.length
const sortedResults = sortResults(results, query, loc)
postMessage({
type: 'results',
@@ -102,7 +104,7 @@ async function performSearch(query: string, loc: string, searchId: number) {
} as ResultMessage)
}
// Yield control between batches
// Yield control between batches to allow new search requests to interrupt
if (i + batchSize < recentDocuments.length && results.length < limit) {
await yieldControl()
}