Skip to content

⚡️ Performance: Don't open client files unnecessarily for project service #8427

Closed
@JoshuaKGoldberg

Description

@JoshuaKGoldberg

Before You File a Proposal Please Confirm You Have Done The Following...

Relevant Package

typescript-estree

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Description

As reported by @yepitschunked in #8322 (thanks! ❤️‍🔥):

The current implementation opens all files using the project service, even if the file is not opted into type-aware linting (with the project or programs options).
This makes linting slower than necessary, since project for every file will be loaded.

I like the idea of not calling service.openClientFile unnecessarily. useProgramFromProjectService is indeed called always if parseSettings.EXPERIMENTAL_useProjectService is true:

function getProgramAndAST(
parseSettings: ParseSettings,
hasFullTypeInformation: boolean,
): ASTAndProgram {
if (parseSettings.EXPERIMENTAL_projectService) {
const fromProjectService = useProgramFromProjectService(

Logs in #8424 show that opening files with a warmed-up project service to take a few ms per file. That can really add up in projects with many files.

#8322 (comment) shows that avoiding calling service.openClientFile on files that don't ask for type checking can speed up service-type-checked linting to be on par with traditional type-checked linting. ⚡

Additional Info

Note that I'm not yet convinced that #8322's starting approach is the correct one. That approach only calls openClientFile on files with type-checked linting enabled. But some users enable type information on all files despite only using it in some. And, heck, type-checked rules only use type checking conditionally - and try to avoid calling it if they can bail out early. So gating openClientFile on whether a file wants type information can still allow files through the gate unnecessarily.

An alternative possibility might be to avoid opening the client file altogether until getParserServices is called within a lint rule. I think that's the best possible strategy for avoiding unnecessary openClientFile calls. But that might require moving all the type generation logic to getParserServices... which might be good in general? Investigation required.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancementNew feature or requestlocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.performanceIssues regarding performance

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions