-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
~50x regression in type instantiation count between 3.3 and 3.4 #30819
Comments
tsconfig.json
|
Investigation notes
|
So, the change that introduced the perf issue is a change that caused us to instantiate the From the declaration side, it's obvious that the instantiation becomes expensive because From the implementation side, these types are expensive because of how we handle distribution. We have this thing called a "distributive constraint" - there's a number of issues open W.R.T. it's unsoundness, but on top of that, the distributive constraint works as a constraint-based work multiplier. Rather than lazily deferring work, the distributive constraint eagerly partially evaluates conditionals in an attempt to "narrow" them while looking at constraints. It does this very inefficiently - every instantiation has to go back to the root conditional and re-instantiate and re-narrow; there is no "progressive instantiation" as most other types (ie, indexed accesses) have (instead the mapper is used as a transform which we we apply over and over onto a different base In short, the pattern we have of using a conditional type's If we could find a way to safely reduce or remove usages of So, this leads me to question our current construction of distributive conditionals and its inefficiency: Why are they as they are? Simply because the current formulation makes is easy to track substitutions as they occur - we don't need to worry about remapping any instantiables within the branches. However this seems unfortunate - we'd really like to be able to say, when |
The notes from @RyanCavanaugh seem to imply that the fix in DT on Using the latest Aside from raw Comparatively, the VSCode integration is workable with When testing with TypeScript |
@alex-sherwin those numbers were with |
Here's my benchmark against different typescript version. tsconfig.json {
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"lib": ["esnext", "dom", "dom.iterable"],
"allowJs": false,
"allowSyntheticDefaultImports": true,
"esModuleInterop": false,
"isolatedModules": true,
"jsx": "preserve",
"noEmit": true,
"skipLibCheck": true,
"strict": true,
"baseUrl": ".",
"paths": {
// maps for webpack alias
"Apollo/*": ["src/apollo/*"],
"Components/*": ["src/components/*"],
"Utils/*": ["src/utils/*"],
"Admin/*": ["src/app/admin/*"],
// custom types for modules
"*": ["src/@types/*"]
}
},
"include": ["src"]
} Project Dependencies (reduced for clarily) {
"scripts": {
"typecheck": "tsc --noEmit"
},
"devDependencies": {
"@babel/plugin-transform-runtime": "^7.4.4",
"@commitlint/cli": "^7.5.2",
"@commitlint/config-conventional": "^7.5.0",
"@wpackio/eslint-config": "^3.2.0",
"@wpackio/scripts": "^3.3.0",
"apollo": "^2.9.0",
"babel-plugin-import": "^1.11.0",
"babel-plugin-styled-components": "^1.10.0",
"conventional-changelog-cli": "^2.0.17",
"cross-env": "^5.2.0",
"cssnano": "^4.1.10",
"eslint": "^5.16.0",
"eslint-plugin-react-hooks": "^1.6.0",
"fork-ts-checker-webpack-plugin": "^1.3.0",
"husky": "^2.2.0",
"less": "^3.9.0",
"lint-staged": "^8.1.5",
"node-sass": "^4.12.0",
"prettier": "^1.17.0",
"typescript": "3.3",
"use-yarn": "^2.2.0",
"webpack-bundle-analyzer": "^3.3.2"
},
"dependencies": {
"@babel/runtime-corejs3": "^7.4.4",
"@rehooks/component-size": "^1.0.2",
"@types/graphql": "^14.2.0",
"@types/react": "^16.8.15",
"@types/react-dom": "^16.8.4",
"@types/react-router-dom": "^4.3.2",
"@types/styled-components": "^4.1.14",
"@wpackio/entrypoint": "^3.2.0",
"antd": "^3.16.6",
"apollo-boost": "^0.3.1",
"core-js": "^3.0.1",
"graphql": "^14.2.1",
"react": "^16.8.6",
"react-apollo": "^2.5.5",
"react-content-loader": "^4.2.1",
"react-dom": "^16.8.6",
"react-router-dom": "^5.0.0",
"styled-components": "^4.2.0"
}
}
|
@weswigham I see you marked this as Fixed, but I don't see the actual commit with a fix. Would you mind providing some info? |
@havenchyk Hey man, I know you’re not asking me, but the issue seems to have been fixed with the release of Typescript 3.5.0-rc. I believe it’s discussed a bit here: https://devblogs.microsoft.com/typescript/announcing-typescript-3-5-rc/. |
Yeah, I see a note about it, thanks for sharing @maxmathews! TBH, locally I still have better results with 3.3 version comparing to 3.5.RC, but it's not that bad as it was for 3.4. So thanks 🙏 |
@havenchyk no problem! |
Yea I will say also, it’s still very slow for me.
|
Y'all have a repro and some numbers we can look at? |
How do you benchmark? I see visible lag in VSCode a few seconds that I didn't have previously. Things in the code have changed since then, so I can't know it's compiler or new code, but If I correct an error the red error lines actually stay in the wrong place and the entire editor feels sluggish for a few seconds. Autocomplete is also delayed ~2 seconds most times. Happy to run some comparison, not sure best way to do it. |
If the code's public, just linking it and some repeatable instructions'd be best. Failing that, if you launch vscode from the command line with the |
I'm running I do think this may still be related this this slowdown: #29949 Not to bitch but perhaps it helps, my current setup is quite borked between microsoft/vscode#25312 and this, I'm restarting TS server many times a day, waiting 20+ seconds for it to load, and when it does run it's now oftentimes 5+ seconds delayed (on a 2.9 i9 quad code no less). I'd love to be of any help to get some of this figured out! |
TypeScript Version: 3.4.0
Search Terms: slow styled-components
Code
Expected behavior: Type instantiation count < ~10k, check time < 0.1s
Actual behavior: Instantiation count ~47k, check time ~2.5s
The text was updated successfully, but these errors were encountered: