question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cache importFixes/fixMissingImport in getCodeFixes requests

See original GitHub issue

Search Terms

  • getCodeFixes cache

Suggestion

In tsserver, the completionInfo request benefits from a cache of import suggestions.

https://github.com/microsoft/TypeScript/blob/d156bb805eba314be2fbe86e4c4ca0179380580e/src/services/completions.ts#L1627-L1631

Could the getCodeFixes request be extended to use a suggestion imports cache as well?

https://github.com/microsoft/TypeScript/blob/2428ade1a91248e847f3e1561e31a9426650efee/src/services/codefixes/importFixes.ts#L234

Both call codeFixes.forEachExternalModuleToImportFrom, which can be very slow in a large project. Thanks!

Checklist

My suggestion meets these guidelines:

  • This wouldn’t be a breaking change in existing TypeScript/JavaScript code
  • This wouldn’t change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn’t a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript’s Design Goals.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
andrewbranchcommented, Jan 22, 2021

That’s great to hear! It seems like this issue is lower priority now, though there are definitely still worthwhile improvements that could be made. I’m going to bump it to the backlog for now.

1reaction
gluxoncommented, Jan 22, 2021

@andrewbranch So I was following #40584, but didn’t think it applied to my project since it uses yarn instead of pnpm. I could not have been more wrong. After pulling your change in #42150, getCodeFixes finishes in ~650ms. That’s a 14x improvement from the ~9s previously.

Thank you so much! 🎉

This project uses yarn workspaces to symlink its ~500 monorepo packages into node_modules, so that’s likely why the fix ended up carrying over.

I’ll leave the status of this issue up to the discretion of the TypeScript team. (Feel free to close it.) When I was filing it, I never expected getCodeFixes to get that drastic of a performance improvement and thought it should be at least cached. But that cache isn’t necessary now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found