-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Emotion 10 greatly increases number of types during TypeScript compilation #1496
Comments
Could u also add comparison with styled-components? |
Done, it is about double the number of types of emotion 9, but way less than emotion 10 still |
Interesting. Maybe u could narrow down the explosion of types to some lines by bisecting our typings? |
Yeah will be doing that, thought i'd just raise the issue for visibility first. Another interesting data point: Emotion 9, with 2 components: 2803 types (1.60s @ 110,600K) Not a huge amount of increase for any of the components. Gonna have to play around with themes and props too it seems (we use both of those heavily). Otherwise I am unsure how we got such a 600k type increase in our project. |
Out of curiosity - when perf hits you? Do you have problem with initial compilation? recompilations? Do you use incremental builds feature? |
We are using ts-loader so the PR's enabling incremental complication only merged in the last day. We often run webpack without type checking (the out of process stuff caused me all sorts of issues with client dev tools builds getting server chunks for some reason) then use tsc to type check. I haven't setup the incremental builds feature yet, on the todo list. Was kinda waiting for ts-loader to ship support for incremental build |
beta.4: Types: 6324 This is just the single component version. So beta 4 increased the types by quite a bit, but between beta 4 & 6 is when the large jump came in. You can have a look at the changes in JakeGinnivan/emotion-types-sandbox@9612ac9 |
FYI @Ailrun @mitchellhamilton, any ideas welcome :) |
That's the diff between beta.4 and beta.6 - 2a9a1b8...db5ccda So looking at its contents this might be the offender: |
So in my sandbox project I have copied out the .d.ts files from the project at various versions so we can easily check performance of just types at a version. JakeGinnivan/emotion-types-sandbox@9612ac9 lists the diff between beta.4 and beta.6 of just the types. In @emotion/serialize/index.d.ts, changing And getting rid of that Equal type Drops the number of types from 11015 to 6840. That brings it back to close to beta.4 levels. Still not back to emotion 9 levels but much better. |
Seems like this could be inlined, as both seem equivalent, OTOH emotion uses conditional types etc extensively - we just can't get rid all of them. |
If we remove Equals entirely and remove the circular reference from FunctionInterpolation we dropped from 852,685 to 749,563 types.
Working on trying to simplify the CreateStyled types |
Ok, have restructured a bunch of types. I've moved theme related overloads into https://github.com/JakeGinnivan/emotion-types-sandbox/pull/1/files Here are the diagnostics in our application. The number of types are better than they were for emotion 9, same with memory. Time is up because i'm working on battery not plugged in i'm gathering. Files: 2242 Should I put together a PR to emotion? |
It also fixed a few TODOs and type inference issues |
Sure, I'd love to take a look at that. |
There you go, works in our project really well. It does have breaking changes in the types. Not sure how you semver your types. |
I've started looking at a way to be able to catch these issues early with existing dts + js projects also: tsdjs/tsd#34 |
Going to close this issue right now as we plan to land the PR intended to improve this soon and I'd like to keep the issue tracker clean as I'm going through the list daily. |
I am opening this to start a discussion, I plan on debugging it and trying to figure out why but upgrading to emotion 10 increased our project compilation time from ~30 seconds to ~70seconds. Any ideas/help would be great though.
Got these stats by just running
yarn tsc --diagnostics
Current behavior:
Emotion 9:
Emotion 10:
To reproduce:
I wanted to rule out our codebase, so have created a repo project at https://github.com/JakeGinnivan/emotion-types-sandbox
Emotion 10, with 1 styled component:
https://github.com/JakeGinnivan/emotion-types-sandbox
Emotion 9
https://github.com/JakeGinnivan/emotion-types-sandbox/tree/emotion9
Baseline (without emotion):
Styled components:
Summary:
Baseline (just react): 1206 types (1.43s @ 110,732K memory used)
Baseline + 1 emotion 9 styled component: 2793 types (1.46s @ 111,337K memory used)
Baseline + 1 emotion 10 styled component: 11,015 types (2.09s @ 115,850K memory used)
Baseline + 1 styled-components 4.3.2: 4978 types (1.68s @ 125,100K memory used)
Expected behavior:
The emotion TypeScript types need to be simplified
Environment information:
react
version: 16.9.0emotion
version: 10.0.17typescript
version: 3.6.3The text was updated successfully, but these errors were encountered: