Skip to content

Performance slowdown on recursive type in 4.3 and 4.4, fixed in 4.5 #47052

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

Closed
dgieselaar opened this issue Dec 7, 2021 · 6 comments
Closed
Labels
Question An issue which isn't directly actionable in code

Comments

@dgieselaar
Copy link

dgieselaar commented Dec 7, 2021

Bug Report

I'm maintaining a type that infers the response type for an Elasticsearch request based on its input. After upgrading to 4.3.5 in the Kibana repo Intellisense has become terribly slow for us and one place where I see a pretty big slowdown is in these types (which all of our APIs depend on). After manually bisecting some changes between 4.2 and 4.3 I'm suspecting #43527 is the culprit.

The type is a recursive one, but not directly (ie, it calls itself via other types it creates).

From looking at the trace data that TS itself generates and profiling via pprof I see a lot of time is being spent in getVariancesWorker (via getAliasVariances) and recursiveTypeRelatedTo/structuredTypeRelatedTo.

Is there a better way to write these types that work with 4.3 and 4.4 in a reasonable manner? If not, is it possible that whatever fixed it in 4.5 is backported to 4.3? I'm not expecting is to be able to upgrade to 4.5 any time soon, we just completed a painful upgrade to 4.3.

🔎 Search Terms

recursive type, tail-recursive, union, map, performance, getVariancesWorker, getRecursionIdentity, getVariancesWorker, recursiveTypeRelatedTo, structuredTypeRelatedTo

4.2.3, 4.3.5, 4.4.4, 4.5.2

🕗 Version & Regression Information

This changed between versions 4.2.3 and 4.3.5

⏯ Playground Link

https://ela.st/faster-typescript-es-perf

If you uncomment the bottom line and re-type it you should be able to see a huge difference in responsiveness in 4.2/4.5 vs 4.3/4.4.

💻 Code

See playground link.

🙁 Actual behavior

Autocompletion takes a long time (+5s).

🙂 Expected behavior

Autocompletion should be instant.

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Dec 7, 2021
@RyanCavanaugh
Copy link
Member

The risk/reward calculation for backporting that fix to prior releases doesn't pencil out IMO -- it's too possible that this could break someone else and leave them completely stuck, whereas people needing the fix 4.2 and 4.5 as safe spots.

@dgieselaar
Copy link
Author

The risk/reward calculation for backporting that fix to prior releases doesn't pencil out IMO

What fix are you referring to?

@dgieselaar
Copy link
Author

For folks that stumble upon this issue, we've merged a fix that replaced the mapped object type property access w/ ValuesType<Pick<...>, ...> which gives us similar performance to TS 4.1 and 4.5. https://github.com/elastic/kibana/pull/120754/files

@RyanCavanaugh
Copy link
Member

What fix are you referring to?

The performance fix you're asking be ported

@dgieselaar
Copy link
Author

dgieselaar commented Dec 10, 2021

@RyanCavanaugh I don't know what that fix is (in 4.5+), that's what I'm trying to figure out. I did mention a PR in the description which I think is the reason why things became slower.

@typescript-bot
Copy link
Collaborator

This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow or the TypeScript Discord community.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants