镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

3.4.1 tsc works 20! times slower than 3.3.4 #30663

Description

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)
image

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:
image

3.4.1:
image

Related Issues:

Activity

  1. ulrichb commented on Mar 30, 2019

    @ulrichb

    Same here. I also got some significant performance hit in my front-end build (and I'm also using styled-components).

  2. jazzfog commented on Mar 31, 2019

    @jazzfog

    Same here, rollback to TypeScript 3.3.x temporary fixed the problem.

  3. quolpr commented on Mar 31, 2019

    @quolpr

    Same issue here, switched back to 3.3.x

  4. ulrichb commented on Mar 31, 2019

    @ulrichb

    Maybe related: #29949 and #30449

  5. denis-sokolov commented on Apr 1, 2019

    @denis-sokolov

    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.

  6. dsabanin commented on Apr 1, 2019

    @dsabanin

    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.

  7. ulrichb commented on Apr 2, 2019

    @ulrichb

    I can confirm that a downgrade to @types/styled-components@4.1.10 seems to solve the perf issue.

    Wesley Wigham (@weswigham) So could you maybe revert the concerned commit (probably 6605356e) in the styled-components typings to workaround this issue?

  8. EugeneDraitsev commented on Apr 2, 2019

    @EugeneDraitsev
    Author

    ulrichb I checked downgrade seanario to @types/styled-components@4.1.10 and it still works slower with TypeScript 3.4, but at least not 20times slower, only 2.5 times:

    @types/styled-components@4.1.10 and typescript@3.3.4000:
    image

    @types/styled-components@4.1.10 and typescript@3.4.1:
    image

  9. ulrichb commented on Apr 2, 2019

    @ulrichb

    My observations of the front-end build times (react-scripts build) in a mid-size project:

    • TS 3.4.4000: ~ 2 min 20 sec
    • TS 3.4.1 and @types/styled-components 4.1.12: ~ 3 min 40 sec (+ 1 min 20 sec)
    • TS 3.4.1 and @types/styled-components 4.1.10: ~ 2 min 40 sec (+ 20 sec)

    @ TS Team: Note that my problem is not really the additional ~1 min 20 sec in the build script, but that my IDE (WebStorm) time-outs during type-checking => so I don't get any red squiggles in TSX modules containing styled-components (which concerns almost my whole front-end code base) :/ A downgrade to styled-components 4.1.10 solves/workarounds this issue.

  10. EugeneDraitsev commented on Apr 2, 2019

    @EugeneDraitsev
    Author

    ulrichb you compared build time, but not tsc time. The main problem here right now, that typecheking with IDE or by cli works significantly slower, or 2-2.5 times slower if you will use @types/styled-components 4.1.10. On mid-size project I have ~4s vs ~12s on @types/styled-components 4.1.10. This timings are still kind of workable, but it should be the same as on 3.3.4000 (or at least +5-20% of it)

  11. voliva commented on Apr 3, 2019

    @voliva

    Yesterday, without looking for the issue in this repo, I opened this issue in @types/styled-components DefinitelyTyped/DefinitelyTyped#34391.

    Michelle Saad (@michsa) saw that the performance change was done between the builds typescript@3.4.0-dev.20190223 (working normally) and 3.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.

  12. 34 remaining items

  13. FishOrBear commented on May 13, 2019

    @FishOrBear

    I am using typescript@3.5.0-dev.20190512

    tsc --noEmit

    Still a memory leak and crash.

  14. weswigham commented on May 13, 2019

    @weswigham
    Member

    Still a memory leak and crash

    You have a repro you can share?

  15. FishOrBear commented on May 14, 2019

    @FishOrBear

    Wesley Wigham (@weswigham)
    test.zip

    I think it may be a similar problem.

    #31227

  16. weswigham commented on May 20, 2019

    @weswigham
    Member

    Mike Erickson (@FishOrBear) Your crash is fixed in the latest nightlies and the rc.

  17. FishOrBear commented on May 21, 2019

    @FishOrBear

    Wesley Wigham (@weswigham)
    Thank you, I have tried the latest package, now there is no problem.

  18. wilcoxmd commented on May 30, 2019

    @wilcoxmd

    Hi there, I'm trying to fix this issue myself and having a hard time understanding which versions of @types/styled-components, etc. to use to solve the problem. I'm currently using:

    react-scripts@3.0.1
    @types/styled-components@^4.1.14
    styled-components@^4.2.0
    typescript@^3.5.1

    I'm using VS Code and still having some noticeable delays for things like underlining type errors in files that use styled-components. Commenting out any styled components removes the delay. Am I missing a package upgrade somewhere?

  19. wilcoxmd commented on May 30, 2019

    @wilcoxmd

    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.

  20. cyrus-za commented on Jul 1, 2019

    @cyrus-za

    Having a similar issue. See react/create-react-app#7003

  21. weswigham commented on Jul 1, 2019

    @weswigham
    Member

    If you're still on an older version of TS that has the problem, you're still going to have the issue ❤️

    I'm going to lock this issue - anyone with a perf problem on the latest version of TS has a distinct and different problem and should open a new thread. Anyone finding this from google search results and is looking for a solution - try using TS 3.5+ (and then if your problem persists, let us know in a new issue), or try downgrading your @types/styled-components version to 4.1.14 (if you must stay on an older version of TS), thanks~

  22. locked as resolved and limited conversation to collaborators on Jul 1, 2019
  23. added
    BugA bug in TypeScript
    FixedA PR has been merged for this issue
    and removed
    Needs InvestigationThis issue needs a team member to investigate its status.
    on Jul 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions