Skip to content
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

fix: slow intersections on IAzureLayerStatefulProviderProps type #228

Merged
merged 1 commit into from
Feb 25, 2025

Conversation

Weffe
Copy link
Contributor

@Weffe Weffe commented Feb 22, 2025

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 of IAzureLayerStatefulProviderProps some devs saw a slowdown to 90s and without caching upwards of 5mins-10mins. We found that by removing any reference to IAzureLayerStatefulProviderProps and deleting its import then TypeScript would resume back to normal performance levels.

I found that if we replace the intersections (&) with interface + 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 an interface TS does some extra perf tricks and is why they recommend interfaces over intersections on their performance wiki

You 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 the types.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.

image

Copy link
Contributor

@yulinscottkang yulinscottkang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you!

@dubiety dubiety merged commit 21f34bf into Azure:master Feb 25, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants