Skip to content

Unexpected very poor performance #38970

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
CyberPhoenix90 opened this issue Jun 7, 2020 · 1 comment · Fixed by #42727
Closed

Unexpected very poor performance #38970

CyberPhoenix90 opened this issue Jun 7, 2020 · 1 comment · Fixed by #42727
Assignees
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status. Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@CyberPhoenix90
Copy link

CyberPhoenix90 commented Jun 7, 2020

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

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Jun 8, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.0 milestone Jun 8, 2020
CyberPhoenix90 added a commit to CyberPhoenix90/aurum that referenced this issue Jun 13, 2020
@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label Aug 31, 2020
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Feb 9, 2021
@weswigham
Copy link
Member

weswigham commented Feb 9, 2021

I have a fix. Better yet, I have two potential fixes: #42726 and #42727. The first is more complete, but has the potential to cost more overall when the heuristic doesn't apply, while the optimization in the second is less broad, but very cheap to check. Both rely on the same philosophy that an ongoing comparison which would imply the result of the current comparison should lend its result to the current comparison.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status. Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
4 participants