Skip to content

perf: optimize hot paths in build pipeline#687

Closed
Copilot wants to merge 4 commits intomainfrom
copilot/improve-slow-code-efficiency
Closed

perf: optimize hot paths in build pipeline#687
Copilot wants to merge 4 commits intomainfrom
copilot/improve-slow-code-efficiency

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 3, 2026

Several algorithmic inefficiencies were causing unnecessary overhead during builds, particularly in large projects with many dependencies and CSS files.

Changes

Path resolution (src/utils/fs.ts)

  • Remove duplicate slice() call in lowestCommonAncestor loop
  • Add early exit when no common ancestor exists

External dependency resolution (src/features/external.ts)

  • Replace Array.some() with Set-based O(1) lookups for exact package matches
  • Optimize subpath imports (e.g., react/jsx-runtime) to extract package name once
// Before: O(n) linear search per module
deps.some((dep) => id === dep || id.startsWith(`${dep}/`))

// After: O(1) hash lookup
if (depsSet.has(id)) return true
const slashIndex = id.indexOf('/')
if (slashIndex > 0 && depsSet.has(id.slice(0, slashIndex))) return true

CSS code splitting (src/features/css.ts)

  • Replace O(n²) nested chunk-CSS matching loop with indexed O(n) lookup
  • Build chunk name index for O(1) access instead of scanning all chunks per CSS file

Pattern matching (src/utils/general.ts)

  • Cache compiled picomatch matchers to avoid recompilation
  • Add fast path for exact string matches
  • Implement 500-entry cache limit to prevent unbounded growth

Plugin initialization (src/features/node-protocol.ts)

  • Hoist regex compilation to module level (once) instead of per-plugin instantiation

Environment filtering (src/config/options.ts)

  • Check undefined values before expensive prefix matching to short-circuit early
Original prompt

Identify and suggest improvements to slow or inefficient code


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI assigned Copilot and sxzz Jan 3, 2026
@netlify
Copy link
Copy Markdown

netlify bot commented Jan 3, 2026

Deploy Preview for tsdown ready!

Name Link
🔨 Latest commit f675a36
🔍 Latest deploy log https://app.netlify.com/projects/tsdown/deploys/69594c85c5c7bb00085cee2f
😎 Deploy Preview https://deploy-preview-687--tsdown.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI and others added 3 commits January 3, 2026 17:01
…lation, optimize CSS plugin, and improve matchPattern caching

Co-authored-by: sxzz <6481596+sxzz@users.noreply.github.com>
…f Array.some

Co-authored-by: sxzz <6481596+sxzz@users.noreply.github.com>
…e size limit for picomatch

Co-authored-by: sxzz <6481596+sxzz@users.noreply.github.com>
Copilot AI changed the title [WIP] Identify and suggest improvements for inefficient code perf: optimize hot paths in build pipeline Jan 3, 2026
Copilot AI requested a review from sxzz January 3, 2026 17:09
@sxzz sxzz closed this Jan 3, 2026
sxzz added a commit that referenced this pull request Jan 3, 2026
@sxzz sxzz deleted the copilot/improve-slow-code-efficiency branch February 4, 2026 20:14
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.

2 participants