-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Crazy checker.ts refactor experiment (25kloc) #17861
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
😱 wow! Did you see any change in performance? |
@RyanCavanaugh I think no. I didn't write performance tests, but all regular typescript tests run in same time as usual build. |
got an idea how to prevent splitting property declarations and initialisation, using constructor(public host: TypeCheckerHost, public produceDiagnostics: boolean ) It fixes problem of properties dependency. I`ll try it |
@Busyrev as built compiler supports |
I ran our internal performance tests and it looks like there is a large increase in check time. (There were also large increases in emit time, which may just be my hard drive acting up.) There was no change to parse or bind time or memory usage. Monaco - node (v8.2.1, x64)
Monaco - tsc (x86)
TFS - node (v8.2.1, x64)
TFS - tsc (x86)
I'd really like to see the checker cut down to size -- it's so big that vscode doesn't support collapsing code, and it takes several seconds to update errors. I think some of the candidates for removal from |
@Andy-MS thanks for tests! I believe we can beat this 25% slowdown. |
Hi @Busyrev , sorry for the delay. It looks like your branch |
That'll be much easier to refactor incrementally if |
An incremental that could be used is to move some of the variables that It might even make sense to have a couple of objects. I could very easily seen all of the type intrinsics defined grouped together on their own object. I see that |
Can someone explain the performance issues? It seems crazy to me that you can't split up a 41k line file because of that. It makes editing it very difficult - not only the performance issues, but you can't even jump to errors or changes using the scrollbar. |
@Timmmm I think that there is two major performanse issues:
|
This gets asked a ton of times, so here's the short version Imagine you have this code structure function fn(x) {
// There are ~450 of these variables
let y1 = someFunc1(x);
let y2 = someFunc2(x);
// There are ~1200 of these functions
function a() {
console.log(y1 - x);
}
function b(z) {
console.log(y2 + x * z);
}
} It is a fact in modern JS engines that bare-name lookups like |
I don't see discussion of this topic in this PR, but is the a reason you couldn't use a bundler step to ensure production users aren't slowed down? A sufficiently smart bundler could properly inline each of those functions to create the same "output" we have today? -- Preserving the performance wins. Additionally: in your example, Obviously deciding on the right module boundaries is hard, but it feels like checker.ts is creaking under it's own weight and needs that anyways. UPDATE: Whoops, brain-fart. I ran across this from twitter, and didn't process that the most recent comments were from 2021 not from 2022. Sorry for resurrecting. |
I have made tool-assisted refactoring experiment on typeChecker. The goal is to convert checker.ts from incapsulated js scope to a class. For better extensibility and publicity (#17680).
All tests are passing, excluding linting (because of auto converting). We can fix linting issues later.
How I refactored 25k lines of code:
declarations now looks ugly, because
Here is commit in my fork:
Busyrev@697d90e
Unfortunetly GitHub can`t show diff, and that is one more point for necessity of refactoring.
Raw checker.ts before
https://github.com/raw/Microsoft/TypeScript/master/src/compiler/checker.ts
after
https://github.com/raw/Busyrev/TypeScript/checker-class-public-experimental/src/compiler/checker.ts
This is only experiment.
I have spend around 16 hours for these transforms. I think that this experiment is successful.
For better typescript future I think checker.ts should be separated into multiple files/classes, and this is the first step. This code is not merge ready. Of course we should think about methods to be provided to public api, and may be unsafe access for people who do really complicated transformations.
What do you think about it?
I can dedicate more time, improve documents and publish tools I've made, if more people support this experiment.
The text was updated successfully, but these errors were encountered: