Skip to content

isCircularImport complexity impacting Vite performance #20084

@hanford

Description

@hanford

Describe the bug

I have a multimillion LOC codebase that includes >25,000 TypeScript modules.

Our development server currently takes around 3 minutes to start.

We discovered that disabling the isCircularImport check, (or simply returning false), cuts startup time by ~60 to 90 seconds. That check performs a DFS, which runs in O(V + E) time, so its cost becomes significant in a very large codebase with deep dependency chains.

ChatGPT suggested implementing a disjoint set, aka union find which could remove the need for recursion and reduce the check to O(1) complexity.

But I think some small tweaks to the current DFS could get us pretty far, so I've started there!

refs: #20085

System Info

Mac OX 15.1
Vite 6.3.2

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: ssrp2-nice-to-haveNot breaking anything but nice to have (priority)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions