fix: slow intersections on IAzureLayerStatefulProviderProps type #228
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm part of the Kusto team (Azure Data Explorer) and we stumbled upon a recent issue where the type checker would heavily slow down after a change a member on our team did to tighten up types by referencing
IAzureLayerStatefulProviderProps
in our code.This caused type checking (
npm run tsc
) to slow down 10-20x the normal time. Usually for our large project it would take 30s to type check but after the introduction ofIAzureLayerStatefulProviderProps
some devs saw a slowdown to 90s and without caching upwards of 5mins-10mins. We found that by removing any reference toIAzureLayerStatefulProviderProps
and deleting its import then TypeScript would resume back to normal performance levels.I found that if we replace the
intersections
(&
) withinterface
+extends
then the issue is fixed and TypeScript isn't affected by the slowdown. The assumption here is that TS takes a lot longer to squash all the intersected types down to a single type because each intersecting type has complex shapes on its own defined properties. At least with aninterface
TS does some extra perf tricks and is why they recommend interfaces over intersections on their performance wikiYou can try out a repro of the issue here in this Codesandbox
In a terminal, run
npm run typecheck
to get the before stats and then manually edit thetypes.d.ts
file to include the new changes and run again to see the after stats. Here's a screenshot of the stats I saw. A rough 3x increase in type checking speed which matches our experience.