Skip to content

fix(typescript-estree): only run projectService setHostConfiguration when needed #9336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

higherorderfunctor
Copy link
Contributor

@higherorderfunctor higherorderfunctor commented Jun 11, 2024

PR Checklist

Overview

Moves ProjectService.setHostConfiguration from useProgramFromProjectService where it is called on every source to createProjectService where it is only called once per ProjectService. See comments regarding updated implementation.

ProjectService.setHostConfiguration reloads the whole project. The way vue-eslint-parser sends template fragments causes a reload to start and then get canceled for n - 1 template fragments per file.

This fix along with #9223 if using eslint-plugin-import/eslint-plugin-import-x vastly improves performance.

I am open to suggestions on improving the signature of createProjectService. I appended as a new 3rd argument called parseSettings which is an object to allow for additional settings to be added in the future if needed. I could see this being merged with the second argument, but I was not sure of the implications in making a breaking change to the existing signature.

…tService

Calling on every source causes a full graph update.  Relocating to call
once per ProjectService.
@typescript-eslint
Copy link
Contributor

Thanks for the PR, @higherorderfunctor!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint.

Copy link

netlify bot commented Jun 11, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit e081759
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/6677155e685e6a0009479df1
😎 Deploy Preview https://deploy-preview-9336--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 99 (🟢 up 1 from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 90 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

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

Copy link

nx-cloud bot commented Jun 11, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit e081759. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@higherorderfunctor higherorderfunctor changed the title perf(typescript-estree): moves setHostConfiguration into createProjectService fix(typescript-estree): moves setHostConfiguration into createProjectService Jun 11, 2024
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Tentatively looks lovely to me, with the refactor suggestion factored in. I'll take a deeper look once I have a chance to play with a repro.

cc @jakebailey as an FYI for this & the issue 🙂

@higherorderfunctor
Copy link
Contributor Author

Thanks for the initial review. I did discover one bug that is fixed in my branch with a collection of changes. If a user changes extensions from the initial ones, they do not get updated. I'll carry the fix in and add a test.

@higherorderfunctor
Copy link
Contributor Author

higherorderfunctor commented Jun 14, 2024

Taking out of draft. Notable updates:

  • Discovered a bug when changing extraFileExtensions in the same linting session.
    • Added positive and negative test cases for this situation.
  • Moved the logic back to packages/typescript-estree/src/useProgramFromProjectService.ts.
  • The approach now caches the last set extraFileExtensions and only calls setHostConfiguration when there is a difference.
    • I'm caching directly on the ProjectService with __extra_file_extensions so it gets garbage collected with clearTSServerProjectService. If you prefer a proper cleanup with it's own function, I can do so, but it may take a few days to find availability.
    • Using sets yielded the best performance when testing hence the symmetricDifference logic. I did not exhaustively look at other options, just some tests iterating with for-loops. Let me know if you want a different approach.
  • I've added documentation to the site explaining how to minimize project reloads by setting extraFileExtensions only once.

This is part of a larger set of changes discussed on #9312 (comment) and #8835 (comment).

@higherorderfunctor higherorderfunctor changed the title fix(typescript-estree): moves setHostConfiguration into createProjectService fix(typescript-estree): changes setHostConfiguration to only run when needed Jun 14, 2024
@higherorderfunctor higherorderfunctor marked this pull request as ready for review June 14, 2024 03:01
…ed and clean up impl

Fixes the test where it should not update to update twice with the same
values to demonstrate the cache worked.

Changes the cache to not update until successfully applied and cleans up
the implementation a bit.
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

I like the direction! Just requesting changes on docs & some of the implementation bits.

Cat head shaking on what looks like a hyperspeed background, implying high speed

…tensions tests

Empty or not provided extraFileExtensions are handled differently
depending on the state of ProjectService.  Clarified test names and
added additional tests to reflect this.
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Looks great to me, thanks! 🙌

Mostly touching up on the docs FAQs. I think they're pretty close, just need some reordering and trimming.

@JoshuaKGoldberg JoshuaKGoldberg added the 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge label Jun 20, 2024
@higherorderfunctor
Copy link
Contributor Author

Made the reordering and trimming changes requested. I also updated the links with the title change in the performance section.

Let me know if any further edits are needed!

Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Lovely, thanks for this! 🙌

I just have docs nitpicks left over. We'll make sure this is merged before our Monday release in two days. 🚀 thanks a bunch @higherorderfunctor!

higherorderfunctor and others added 5 commits June 22, 2024 18:01
Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
@higherorderfunctor
Copy link
Contributor Author

All review suggestions have been committed. Thanks again!

@higherorderfunctor
Copy link
Contributor Author

Inspecting pipeline errors and some of the links aren't rendering locally. Inspecting now.

@higherorderfunctor
Copy link
Contributor Author

Fixes made. So long as the pipeline succeeds, we should be good to merge!

@JoshuaKGoldberg JoshuaKGoldberg changed the title fix(typescript-estree): changes setHostConfiguration to only run when needed fix(typescript-estree): only run projectService setHostConfiguration when needed Jun 22, 2024
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

🔥 ! Very excited to get this released, thank you! A bit of a relief to fix such a disruptive performance issue for Vue users.

I'll merge this in now, merge #9024 into main, and then merge main into v8 - so all the FAQs including this one will be nicely organized.

@JoshuaKGoldberg JoshuaKGoldberg merged commit d1ddbc2 into typescript-eslint:v8 Jun 22, 2024
64 of 65 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants