Skip to content

Unexpected very poor performance #38970

Closed
@CyberPhoenix90

Description

@CyberPhoenix90

TypeScript Version: 3.9.5

Search Terms:
performance
Code

export declare type ThenArg<T> = T extends any ? any : T extends PromiseLike<infer U> ? U : T;

export interface InterfaceA<T> {
	filter(callback: (newValue: T, oldValue: T) => boolean): InterfaceA<T>;
	map<D>(callback: (value: T) => D): InterfaceA<D>;
	await<R extends ThenArg<T>>(): InterfaceA<R>;
	awaitLatest<R extends ThenArg<T>>(): InterfaceA<R>;
	awaitOrdered<R extends ThenArg<T>>(): InterfaceA<R>;
}

export interface InterfaceB<T> extends InterfaceA<T> {
	map<D>(callback: (value: T) => D): InterfaceB<D>;
	await<R extends ThenArg<T>>(): InterfaceB<R>;
	awaitLatest<R extends ThenArg<T>>(): InterfaceB<R>;
	awaitOrdered<R extends ThenArg<T>>(): InterfaceB<R>;
}

export class A<T> implements InterfaceB<T> {
	public filter(callback: (newValue: T, oldValue: T) => boolean): B<T> {
		return undefined;
	}

	public map<D>(callback: (value: T) => D): B<D> {
		return undefined;
	}

	public await<R extends ThenArg<T>>(): B<R> {
		return undefined;
	}

	public awaitOrdered<R extends ThenArg<T>>(): B<R> {
		return undefined;
	}

	public awaitLatest<R extends ThenArg<T>>(): B<R> {
		return undefined;
	}
}

export class B<T> extends A<T> {}

Expected behavior:
Does not slow down typescript to a crawl
Actual behavior:
Takes 8 seconds to build on its own, makes every single vscode interaction with typescript slow down to a crawl

Playground Link:
https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=45&pc=1#code/KYDwDg9gTgLgBAE2AYwDYEMrDjAnmbAFQAtgA7AQSgHMAeQgPjgF45C5QZyEBnOdMrjgB+foLgAuNhxBcyvOAAUoEALYBLHsAAy6gNbBa6sgDNgUOAFUmoy5LYBuAFBPQkWHGNcoJ9MmwAkmTevv4U9EwA3k4AkCbqqN4AFMjoqKgARn56UklkwADuAGppAK7AUoQANHAQqAglqOWVAJQsTBkQdcACLVJBIX7A4YzOMaroYLQAIgwpaZnZuQBuZRVsbcxM031wA+ahwzMMY+gF6OowtABKMnIKJORUdIxzu-s+Q+HXJ7FnFzBtOguDwrrdONw+I9KDQIm9+sEDl8br8Yv9LgB5KBILAIG53SFsUgwl4MeF7RGfMIo5wAXxcbmg8C8SP8FMG-gAQhECfI+B9DiMorEJlNZvN0llkDk4ElVk11oRNtt3pTDtzZqdzpd8RC+USnrDXklVRzgNyflqAUCQWDeQ9ic84SaEWaLaj0TAsTjgHjwbJCdCncbTazzTSnPTXOAmXA0OgeHwhZ5VGBUMBVOQYPy1UNuYw4NEYmBShlUOpkHB4olzBLFtLcvlimtKjU6g0Wxt2nBOt1elJ88KYjEsDBSlAyHBSvJgPF8ggxlHi6Xy5XRcc61KZXLO0ruzsB8dC7ER8AxxOpzO577Fy5l2WK-xtXa9Q7DaTye7j8PR+PJ9OkGvBdYiXEsH0rT1vXMX1dQDfUgyNMkXTgL8i1Pc9-yvYwbxAu8wNXJ9rWBYBQVg+4oUdRDPxRb90L-S9AOw4CYnpKNGQ8eNExQnlXyTHlInpIA

Hello guys, while I was coding I found that for some reason typescript massively dropped in performance in my project, I isolated the issue to the example above
I also found that doing minor changes e.g. making interfaceB not extend interfaceA but instead make A implement both fixes the issue completely. So this particular way of defining my interfaces seems to trigger a bad code path in typescript.
I've tried different typescript versions including the newest one they all seem to have this issue

Metadata

Metadata

Assignees

Labels

Fix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.RescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions