Skip to content

Commit

Permalink
perf: cache empty optimizer result (#15245)
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev authored Dec 6, 2023
1 parent bd26284 commit 8409b66
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions packages/vite/src/node/optimizer/optimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ async function createDepsOptimizer(
// Ensure that a rerun will not be issued for current discovered deps
if (debounceProcessingHandle) clearTimeout(debounceProcessingHandle)

if (closed || Object.keys(metadata.discovered).length === 0) {
if (closed) {
currentlyProcessing = false
return
}
Expand Down Expand Up @@ -580,9 +580,6 @@ async function createDepsOptimizer(
}

function debouncedProcessing(timeout = debounceMs) {
if (!newDepsDiscovered) {
return
}
// Debounced rerun, let other missing dependencies be discovered before
// the running next optimizeDeps
enqueuedRerun = undefined
Expand Down Expand Up @@ -632,8 +629,10 @@ async function createDepsOptimizer(
`✨ no dependencies found by the scanner or crawling static imports`,
),
)
result.cancel()
firstRunCalled = true
// We still commit the result so the scanner isn't run on the next cold start
// for projects without dependencies
startNextDiscoveredBatch()
runOptimizer(result)
return
}

Expand Down Expand Up @@ -684,10 +683,10 @@ async function createDepsOptimizer(
),
)
firstRunCalled = true
} else {
// queue the first optimizer run
debouncedProcessing(0)
}

// queue the first optimizer run, even without deps so the result is cached
debouncedProcessing(0)
}
}

Expand Down

0 comments on commit 8409b66

Please sign in to comment.