question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unbearably slow typescript definitions

See original GitHub issue

Current behavior:

Some of the built-in types cause type-checking and VSCode intellisense feature to be incredibly, painfully slow.

To reproduce:

This only seems to affect large projects. For me that’s working on https://github.com/vanilla/vanilla (working specifically with react components in library/src/scripts, but it reproduces in other areas as well).

I’ve recorded some gifs of the performance degradation.

Situation Gif
Current Behaviour 2021-02-13 12 43 43
With a slight modification of the type 2021-02-13 12 44 16

Expected behavior:

Intellisense on a machine as powerful as the one I’m using should be instant. (32Gb of RAM, i9 CPU, lightning fast SSD).

Environment information:

  • react version: 16.9.0
  • @emotion/css version: 11.1.3

The slowness cause

Typescript has had a lot of issues recently with various libraries replicating CSS or react types. https://github.com/microsoft/TypeScript/issues/34801#issuecomment-767026973

In this case the cause of the slowness in particular seems to come from this piece of code

https://github.com/emotion-js/emotion/blob/master/packages/serialize/types/index.d.ts#L10-L14

export type CSSPropertiesWithMultiValues = {
  [K in keyof CSSProperties]:
    | CSSProperties[K]
    | Array<Extract<CSSProperties[K], string>> // The Extract<> here.
}

It seems the Extract<> on something with as many properties as this CSSProperties is very slow. What I’ve done for my own personal use was to change the code to

export type CSSPropertiesWithMultiValues = {
  [K in keyof CSSProperties]:
    | CSSProperties[K]
    | Array<CSSProperties[K]>>
}

Now this is may not be the correct type of what’s allowed, as it it then allows multiple values an array of values to be passed to properties that don’t support it. My question is until typescript improves the performance of Extract<> in a situation like this, what do we do?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:11
  • Comments:27 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
Andaristcommented, Apr 15, 2021

DO NOT REORDER YOUR CODE HOPING TO IMPROVE PERF.

And you are telling me this after I’ve implemented an eslint rule for this? 😬

On a more serious note though - thank you for explaining this in more detail. I really appreciate it and it makes more sense now to me (even though I would intuitively think that this is resolved in topological order).

0reactions
Andaristcommented, Jan 20, 2022

IIRC the problems that were recognized in this thread were, sort of, addressed in TS itself so it should work better with the latest version of TS. If there is anything that we can do to improve the situation - let us know. I’m afraid that we don’t have time resources to investigate what exactly causes a slowdown though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript inspections sometimes unreliable and/or slow
There are times when TS inspections are slow -- meaning when I fix an error, WS can take several seconds or even longer...
Read more >
Response is very slow only when more type definitions
We have 201 type definitions and 105 interface definitions in graphql file. neo4j graphql generates SDL file of size around 26 MB (...
Read more >
My typescript is very slow - Reddit
Edit: so tsc --build --clean made it a bit better, files are loading faster, i can hover over stuff and get definitions faster,...
Read more >
TypeScript 3.5 fixes 'unbearably slow' type-checking bug
New release addresses regression in TypeScript 3.4 that impacted both build times and editor operations · Caching optimizations impacting the ...
Read more >
TypeScript slows down a project. Nobody seems to ever point ...
Types keep code maintainable, and protect against any accidentally implicit conversions (rife in JS). Types still exist whether you define them or not,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found