Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,15 @@ export function runOptimizeDeps(

const start = performance.now()

// Show progress for non-debug mode
const depCount = qualifiedIds.length
environment.logger.info(
colors.green(
`Pre-bundling ${depCount} ${depCount === 1 ? 'dependency' : 'dependencies'}...`,
),
{ timestamp: true },
)

const preparedRun = prepareEsbuildOptimizerRun(
environment,
depsInfo,
Expand Down Expand Up @@ -717,8 +726,12 @@ export function runOptimizeDeps(
}
}

debug?.(
`Dependencies bundled in ${(performance.now() - start).toFixed(2)}ms`,
const durationMs = (performance.now() - start).toFixed(2)
const durationS = (parseInt(durationMs) / 1000).toFixed(2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Logic error in time conversion causes precision loss. durationMs is already a string from .toFixed(2), and parseInt(durationMs) truncates the decimal part before converting to seconds.

For example, if the actual time is 1234.99ms:

  • Current code: parseInt("1234.99") = 1234, then 1234/1000 = 1.234s
  • Correct: 1234.99/1000 = 1.23499s

This loses up to 0.99ms of precision in the seconds display. Fix by storing the numeric value first:

const duration = performance.now() - start
const durationMs = duration.toFixed(2)
const durationS = (duration / 1000).toFixed(2)
Suggested change
const durationMs = (performance.now() - start).toFixed(2)
const durationS = (parseInt(durationMs) / 1000).toFixed(2)
const duration = performance.now() - start
const durationMs = duration.toFixed(2)
const durationS = (duration / 1000).toFixed(2)

Spotted by Graphite Agent

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Copy link
Author

Choose a reason for hiding this comment

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

Good catch! Fixed the precision loss issue by storing the numeric duration first. Thanks for the detailed explanation! 👍

debug?.(`Dependencies bundled in ${durationMs}ms`)
environment.logger.info(
colors.green(`✨ Dependencies optimized in ${durationS}s`),
{ timestamp: true },
)

return successfulResult
Expand Down
4 changes: 4 additions & 0 deletions packages/vite/src/node/optimizer/optimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ export function createDepsOptimizer(
;(async () => {
try {
debug?.(colors.green(`scanning for dependencies...`))
logger.info(
colors.green(`Scanning dependencies...`),
{ timestamp: true },
)

let deps: Record<string, string>
try {
Expand Down
Loading