-
-
Notifications
You must be signed in to change notification settings - Fork 223
[perf/refactor]: utils improvements in language-server #2901
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
base: master
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 09ace34 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
About One of the reasons For debugging the language server, you also need to use the
You might want to locate the performance problem using the dev tool first. Some of the bigger problems we know are because of libraries causing poor type-check performance. In that case, it might be better to switch the library in your project or wait for the typescript-go (But it might make some libraries get away with more extreme stuff LOL) |
Thank you for the informative answer @jasonlyu123! This makes sense, and i definitely have to become more familiar with the codebase so i don't do unnecessary changes like caching cached stuff 😄 Being able to debug is definitely the best approach, thanks for giving me more info on how to do this! The reason i'm trying to find performance improvements in the svelte language server is because intellisense is instant in our typescript files, but they're noticeable slower in svelte files. Sometimes so slow that AI is actually faster with autocompletion than waiting for the intellisense to finish loading. I will try debugging more and see if i can find bottlenecks that cause the long loading! |
|
Also, have you checked my other PR's?
Would love feedback on them as well! |
|
When the language server starts, TypeScript will create a "program" object that contains type information about the project. The The first If you could find some hot paths in our code, that would be easier to fix. Otherwise, it'll be hard to figure out if it's a TypeScript problem. Or if it's caused by an inefficiency of our LanguageServiceHost implementation. |
This doesn't seem to be the case in my debugging. For me, the If you want we could do some debugging together on frontend project i work at. It is around 200k lines of Svelte and TypeScript (ca 50/50) - so quite a good test for larger projects. |
|
It's normal for Could you record a CPU profile following the steps I mentioned before? If you need to discuss this privately or if you want to provide the project. You can DM me on Discord. You can find me in the Svelte Discord. |

I'm on a journey to improve the performance the performance of the (amazing) svelte language tools in VSCode, since i'm working a large Svelte project that definitely feels the pain, and so i wanted to start with code that i believe is used quite often and can easily be improved.
Initially i wanted to actually debug hot-code usage in the vscode extension, but still after reading https://github.com/sveltejs/language-tools/blob/master/CONTRIBUTING.md I am struggling to understand how i can get output like console.logs in the debugger of the vscode extension - any help here is appreciated! So the methods i chose to update here are based on "how hot i think they are" and "easy performance improvements".
Now back to the PR. I wanted to change these three methods:
But before doing so, i wanted to ensure that the file had more tests, and while i added the tests for that util file, i decided to add some more tests to the other utils file in case i want to change that one in the future.
In
getTextInRangeandgetLineAtPositioneach offsetAt call with only text will compute getLineOffsets(text) again (because of the default parameter), so:That’s O(n) over the whole text each time, instead of once. So i refactored the code to compute line offsets once.
In
isInsideMoustacheTagthehtml.substringusage allocates a brand new string for every call, so the code is refactored to use String.prototype.lastIndexOf with a fromIndex instead, which scans without allocations