-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Typescript: TSServer: Code Fixes: Import missing imports with a symlinked node_modules folder is very slow #40584
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
Comments
@frederikdekegel Please provide detailed repro steps along with sample code and auto import to invoke so we can investigate this. |
Hi @sheetalkamat, for the repro steps, I described the repro steps in the original issue. Is there anything that is not clear? I will add screenshots of my actions for sure.I do not have access to my laptop before tuesday. As for the code, I can give you my repro, but I do not have experience with github, apart from logging issues. How do I delivery the code to you? |
we have made lot of changes to auto import scenarios recently so we want exact repro steps, code to setup and observe difference. |
Hi @sheetalkamat, Code Steps
Note |
Adding @andrewbranch @jessetrinity to see if this is working as intended or something that can be done.
|
@frederikdekegel you would want to add @andrewbranch and @jessetrinity to private repo so they have access to it |
@andrewbranch, @jessetrinity, you have been invited... |
I am also experiencing this in a pnpm monorepo with a medium-sized nestjs app and a couple of very small shared apps. I also noticed that the auto import suggestions suggest importing packages from Is it possible to ignore that folder in a setting somewhere as a workaround? |
It seems like this is just because of the huge, huge number of symlinks that pnpm creates in a project with a large, interconnected dependency graph like this. Enabling |
@andrewbranch that worked for me! 👍🏽 |
Do you know if import suggestions are now as fast as npm or just better? |
@rhyek not sure if faster, but at least just as fast as it was with yarn or npm. |
@ldiego08 Great! Yeah, that's what I meant, sorry. Thanks for confirming. |
@andrewbranch, Thank you and @sheetalkamat for your effort and time. |
@sheetalkamat I setup a small repro illustrating the difference in VSCode between Yarn & PNPM here: https://github.com/walkerburgin/tsserver-pnpm-repro Here are the suggestions when installing dependencies with Yarn: If you set |
// Edit: I don't think this is actually useful. The duplication is confusing, but it doesn't seem to be directly related to the performance issue. We spent some time looking at this today and I think we may have something useful. I've updated the repro to introduce a second dependency, The thing that's interesting is that
It looks like in this case tsserver is somehow traversing at least three different paths to the same module. It seems plausible that at the scale of a real project this could cause a performance issue? |
i looked at the repro in https://github.com/walkerburgin/tsserver-pnpm-repro specified in #40584 (comment) The error for module resolution failure seems like they are correct as per module resolution logic.
And here is the trace for resolution with
You will note that there is no When
Note how it resolves to sibling folder I am not sure if this is configuration error or not. Depending on that, @andrewbranch the workaround of using |
I don't think If it's helpful, we spent some time trying to profile it this evening. It looks like this is where most of the time is being spent: https://github.com/microsoft/TypeScript/blob/v4.0.5/src/compiler/moduleSpecifiers.ts#L194-L209 With PNPM: And the same action with Yarn: |
To add another anecdotal data point, I've played around a little bit with manually patching tsserver to get a feel for the impact of various hacks/changes. All of these measurements are from
(1) seemed like a nice to have since it doesn't run if the host doesn't support it I'm sure (2) negatively impacts the quality of the suggestions, but maybe it's possible to remove these after the fact instead of in this inner loop? For (3) I added an additional data structure to the symlink cache which maps from the real path to an array of symlinks which point to that real directory. For this specific example/test, Code for (5) is here: release-4.0...jeremydorne:release-4.0-symlinks It feels like it should be possible to get the performance of this back in the same ballpark as Yarn/NPM. I'm not sure I understand this code well enough to put up a PR for 3, but happy to try if it's helpful. |
I work on the same team as @walkerburgin – Internally we have decided to point VSCode to the above forked version of tsserver, and have anecdotally seen a 7-8x improvement from the devs that have tried it thus far. Is there any more information we can provide or any way we could help to contribute a mainline fix? We don't feel great about being on a fork, but folks' VSCode performance was close to unusable without it, so we're willing to help in any way we can 🙂 We really appreciate the engagement and the investigation on this issue so far! |
My team (with @walkerburgin and @styu) recently upgraded our version of tsserver from 4.0.5 to 4.1.2 and observed another increase in I’m generally concerned that each addition to |
Thanks for all the detailed analysis; this is really good stuff! Someone, probably me, will be looking into this later in the release cycle when we’re done getting features and breaking changes in. |
@walkerburgin, are the measurements reported in this table for the codebase you shared, triggering fixes on As a general status update, I think there are a number of fixes and optimizations here that all make sense to implement independently. But I’m most confident about this first step, removing these superfluous pnpm symlinks from the cache as a targeted pnpm-specific fix. It fixes a bug (lots of bad fixes returned) and consequently greatly improves the performance. Separately, I think some variation of your inverted symlink cache probably makes sense and would improve module specifier generation performance for anyone who has a lot symlinks (though it seems unlikely that anyone could compete with the number of symlinks created by pnpm). Also, I really feel like EDIT: I just realized the original repro shared was not from you at all, so we are surely looking at different codebases 🤦 |
Ahh, I'm excited that you had a chance to look at this in detail -- thank you! Yeah, the measurements I shared are from our internal codebase, unfortunately. I'm happy to collect stats and try out fixes if it's helpful. We've got a couple million lines of TypeScript in the repo, so maybe it's an interesting test case. I'm not sure if |
@walkerburgin if you wouldn’t mind taking measurements from #42150, that would be great! The last comment from typescript-bot has an npm link you can use. |
@andrewbranch here's what I'm seeing. Same file and action as before, but a different commit:
Looks better to me! |
Currently using 4.2.0-dev.20210126 and can confirm the fix works. |
Seems this has partially regressed. I'm using 4.4.0-dev.20210522 Type If I accept the completion, it will becomes import useControlled from '.pnpm/@[email protected]_bbe24f3d390b2dd762addfb9b4a0c180/node_modules/@material-ui/utils/useControlled' If I trigger the code fix on undefined |
Regression was somewhere in #43149. I’ll take a look. Thanks @Jack-Works! |
@Jack-Works I was able to recreate some problems like this, but would you mind trying out #44259 to make sure it handles the complexities of a real project? |
@nwparker can you share a repro? |
TypeScript Version: 3.9.7
PS: I am using Angular and therefor cannot try to use a later version of Typescript at this time.
Search Terms:
PNPM Typescript import slow
System
OS: Windows 10
Disk: SSD
Expected behavior:
When using PNPM or another packagemanager that uses a symlinked node_modules folder, the code Auto Import fixes like "Imports x from modules" and "import all missing imports" are performed within a reasonable delay. Preferably on par with NPM. With NPM as packagemanager, the code fixes "Imports x from modules" or "import all missing imports" are much faster.
Actual behavior:
The upgrade to Angular 10, also upgraded Typescript to version 3.9.7. In 3.9, support for code Auto Import fixes for imports from symlinked node_modules folder were added.
So I replaced npm with pnpm, and yes indeed, code Auto Imports fixes do function, however extremely slow.
In PNPM TSServer.log, you can see I performed 2 actions
In Visual Studio Code, the yellow lightblub appeared; I selected OnInit from @angular/core, the import statement was generated after approximately
PNPM: 3 seconds
NPM: < 1 second
PS: Also please note that with NPM, the Yellow Lightblub did not appear but the blue one did.
In Visual Studio Code, I selected a missing import and from the blue lightblub, I selected "Import all missing imports", the import statements were generated after approximately
PNPM: 51 seconds
NPM: 2 seconds
This is the NPM TSServer.log.
When doing each action, CPU was at 100%.
.
Related Issues:
The text was updated successfully, but these errors were encountered: