TypeScript: 3.4.1 tsc works 20! times slower than 3.3.4
TypeScript Version: 3.4.1
Search Terms:
tsc, slow, typecheck, 3.4.1, styled-components
Code
I have simple typecheck script in my package.json:
"typecheck": "tsc --project tsconfig.json --noEmit --skipLibCheck",
It work 20 times slower on 3.4.1, than on 3.3.4000 (91s vs 4.5s)
It’s almost impossible to work with that, because IDE almost can’t analyse anything in this conditions. I have same behaviour on MacOS 10.14.3 and on Windows 10
My tsconfig file:
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve"
},
"include": [
"src"
]
}
EDIT: I found the reason of this slowness - styled-components, so faster way to reproduce this issue: (also online demo added below)
yarn create react-app my-app --typescript
cd my-app
yarn add styled-components @types/styled-components
add to src/index.tsx
:
import styled from 'styled-components'
const Styled = styled.div``
add in package json tsc script in scripts section:
"tsc": "tsc"
run yarn tsc
if you’ll downgrade typescript version to 3.3.4000 or comment 2 lines of code in src/index.tsx
it will work 20 times faster
Expected behavior:
It should works with same acceptable time
Actual behavior:
It works 20 times slower
Playground Link:
I will try to create reproducible example, but I have pretty simple react CRA 2.0 application.
EDIT: Reproducible demo here: https://repl.it/@EugeneDraitsev/slow-tsc-341
3.3.4000:
3.4.1:
Related Issues:
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 107
- Comments: 48 (13 by maintainers)
Commits related to this issue
- fix: 绑定Typescript版本为3.3,避免styled-components 检查巨慢问题 相关Typescript [issue](https://github.com/Microsoft/TypeScript/issues/30663) — committed to ivan-94/jm-cli by ivan-94 5 years ago
- WIP: all the misc ts stuff — committed to gatsbyjs/gatsby by moonmeister 5 years ago
- Downgrade TypeScript to 3.3.4000 New version is multiple times slower (takes 8 seconds with new version, half a second with old) Wait until https://github.com/Microsoft/TypeScript/issues/30663 is fix... — committed to codesandbox/codesandbox-client by CompuIves 5 years ago
- Downgrade of TypeScript to v3.3 and upgrades See https://github.com/Microsoft/TypeScript/issues/30663 — committed to grubersjoe/reflow by deleted user 5 years ago
- Implement Redux-controlled progress bar - This commit also fixes lag caused by styled-components types and TypeScript by downgrading. https://github.com/Microsoft/TypeScript/issues/30663 — committed to WilsonCWong/react-ts-boilerplate by WilsonCWong 5 years ago
- Fix styled-components performance - Styled Components types were not playing well with TypeScript 3.4. Downgrading to 3.3.3333 until it is fixed in 3.5. https://github.com/Microsoft/TypeScript/issues... — committed to WilsonCWong/react-ts-boilerplate by WilsonCWong 5 years ago
- ruller @types/styled-components tilbake. Etter bump fra typescript 3.3.* til 3.4.* ble det noe tull med typesystemet som gjorde at typesjekkinga tok evigheter. Følg med her for å se når det er løst: ... — committed to navikt/modiapersonoversikt by deleted user 5 years ago
- downgrade typescript to 3.3 (https://github.com/Microsoft/TypeScript/issues/30663#issuecomment-482051710) — committed to karifrederiksen/painter by karifrederiksen 5 years ago
Catastrophic since new VsCode release which ship with 3.4.1 by default, It took me hours to figure out that 3.4.1 was the issue.
FYI, I’ve done some preliminary investigation, and the performance impact is caused by a large union of types (eg, the union of all possible jsx components) being pushed thru multiple layers of distributive conditionals with nested
infer
types (the constraints on the generics within@types/styled-components
do this by pushingkeyof JSX.IntrinsicElements
thruReact.ComponentPropsWithRef
and then using it a bunch). The distribution has a multiplicative effect on work done. I’m still researching a performance fix in the compiler itself; however at least within@types/styled-components
, I believe you can prevent the perf regression from triggering by removingPickU
(usingPick
instead), and explicitly writing a single distributive conditional aroundStyledComponentProps
(rather than sprinkling extra distributions in everywhere).Same here. I also got some significant performance hit in my front-end build (and I’m also using
styled-components
).Autcomplete was so slow it was very hard to work on anything
Changing ts version for vs code helped.
I tried downgrading to @types/styled-components v4.1.10, but still see unbelievable slowdown on TS versions >= 3.4.0.
It’s a big project, with lots of dependencies so it’s hard to pinpoint what exactly is triggering it, but right now compilation is so slow that development is nearly impossible – 80 seconds for every compile, 75 secs in type checking. WebStorm can’t even recompile the code because of the timeouts. Fans are spinning like crazy on i7, 4x2 HT cores, 42 GB RAM, 4GB node heap iMac. I don’t think we can wait until 3.5.0 for the fix, it would just mean that we would just need to skip 3.4.0 entirely. Disabling strict function type checking is a very radical decision for a complex project.
Hey, anyone on the old version of
@types/styled-components
, based on my own testing, it seems like #30637 actually is what fixed this onmaster
- meaning the currenttypescript@next
already contains a fix. Would love some feedback on if that’s true for your projects which are more complex than a just-initialized CRA template. But in other, more important news: #30637 is a breaking change (though we don’t think it should actually unduly affect anyone unless it’s pointing out real bugs!), meaning we will not be backporting it to 3.4 (😲), at least as-is. So if your@types/styled-components
version is locked to the version with bad perf in 3.4, you’ll want to try to use the TS nightly, at least for now. Likewise, if your TS is locked to3.4
, you’ll want to either downgrade to an older version of@types/styled-components
, or upgrade to a newer version of@types/styled-components
that was pushed today that has the types which triggered bad perf on 3.4 removed.– https://github.com/DefinitelyTyped/DefinitelyTyped/pull/34499#issuecomment-480225465
I have investigated this with TypeScript 3.4.1, and the issue does not show up (for me) with @types/styled-components v4.1.10, but does happen with @types/styled-components v4.1.11. The change between these two versions is related to distributing over union types. Perhaps this helps figure it out.
Same ~x2 time slowdown for me too:
typescript@3.3.4000
and@types/styled-components@4.1.14
: ~8.80s.typescript@3.4.2
and@types/styled-components@4.1.14
: ~18.01stypescript@next
and@types/styled-components@4.1.14
: ~15.40s.@weswigham Should we reopen this issue or open another one?
@cbdeveloper @qmcree The main fix should be released in 3.5, you can try the
next
tag for now to see if it works better.That’s the one I tested on and it was a huge improvement.
Although performance was improved in the newer versions, there is still a significant slowdown running
tsc
. Benchmarks:typescript@3.4.2
and@types/styled-components@4.1.14
: ~7.5 secondstypescript@3.3.4000
and@types/styled-components@4.1.12
: ~3 secondsI am using
typescript@3.5.0-dev.20190512
tsc --noEmit
Still a memory leak and crash.
Yesterday, without looking for the issue in this repo, I opened this issue in @types/styled-components https://github.com/DefinitelyTyped/DefinitelyTyped/issues/34391.
@michsa saw that the performance change was done between the builds
typescript@3.4.0-dev.20190223
(working normally) and3.4.0-dev.20190226
(taking a long time)Maybe it’s worth to cross the info on both threads to find down the root of this issue.
Actually I just figured it out. My VS Code workspace was still using 3.4.5. Changing the workspace to use 3.5.1 fixed the problem.
I think https://github.com/Microsoft/TypeScript/issues/30819 should already cover the lesser perf regression.
3.5, yes. 3.4 series, no. #30637 isn’t a bugfix level change, even though it does fix this - it has other major typesystem effects which we’re not comfortable publishing as a patch.
That’s really unfortunate. The fix likely responsible for the performance regression was applied before 3.4 was released. We couldn’t detect major performance regressions so it seemed fine.
The same fix was also applied to
react-router
(withRouter
),@emotion/styled
and@material-ui/core@next
(withStyles
). Can somebody who uses those packages confirm if 3.4.1 has the same performance issues with those packages?I am also experiencing a significant slow-down after upgrading TypeScript from 3.3.4000 to 3.4.1. As a result, live IDE type checking is almost inoperable. Also have
styled-components@4.2.0
and@types/styled-components@4.1.12
installed.I tried
typescript@next
which pulled downtypescript@3.5.0-dev.20190509
and this does resolve the performance issue. Guess we’ll wait for the 3.5 release before we upgrade TypeScript.EDIT: Installing @types/styled-component didn’t solve my problem. But I downgraded VSCode from 1.33 to 1.32 and now it’s fixed.
I was having problem with slow intellisense on VScode on my JS (React) project. I am also using
styled-components v^4.1.3
.Not sure if this is going to help, but I can confirm that all issues are now fixed, since I’ve installed
@types/styled-components v^4.1.14
(I installed the latest). The intellisense now is perfectly responsive and very fast. I don’t havetypescript
installed globally or locally.Not sure, but I think this issue began when updated to VScode 1.33. Auto-updates are on, though, and as it slowly started to bother me, it might have been happening since an earlier version, but not too long ago.
@weswigham I checked out
next
and it seems like it significantly sped up the build times (1.67 mins to 9.72s). Maybe some others can chime in with their results too?@fabb: May 2019, as per roadmap.