-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Cache accessibe symbol chains and serialized type parameter name generation #43973
Merged
weswigham
merged 5 commits into
microsoft:master
from
weswigham:declaration-emit-performance
May 12, 2021
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0f4e922
Cache accessibe symbol chains, type parameter name generation
weswigham 60be8f1
Move signature declaration helper length approximation to start of fu…
weswigham 52499b1
Add node result caching internal to `typeToTypeNodeHelper`
weswigham 1360db8
Suggestion from PR
weswigham 909d519
Merge branch 'master' into declaration-emit-performance
weswigham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
tests/baselines/reference/declarationEmitPrivatePromiseLikeInterface.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
tests/cases/compiler/Api.ts(6,5): error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. | ||
tests/cases/compiler/Api.ts(7,5): error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. | ||
tests/cases/compiler/Api.ts(8,5): error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. | ||
|
||
|
||
==== tests/cases/compiler/http-client.ts (0 errors) ==== | ||
type TPromise<ResolveType, RejectType = any> = Omit<Promise<ResolveType>, "then" | "catch"> & { | ||
then<TResult1 = ResolveType, TResult2 = never>( | ||
onfulfilled?: ((value: ResolveType) => TResult1 | PromiseLike<TResult1>) | undefined | null, | ||
onrejected?: ((reason: RejectType) => TResult2 | PromiseLike<TResult2>) | undefined | null, | ||
): TPromise<TResult1 | TResult2, RejectType>; | ||
catch<TResult = never>( | ||
onrejected?: ((reason: RejectType) => TResult | PromiseLike<TResult>) | undefined | null, | ||
): TPromise<ResolveType | TResult, RejectType>; | ||
}; | ||
|
||
export interface HttpResponse<D extends unknown, E extends unknown = unknown> extends Response { | ||
data: D; | ||
error: E; | ||
} | ||
|
||
export class HttpClient<SecurityDataType = unknown> { | ||
public request = <T = any, E = any>(): TPromise<HttpResponse<T, E>> => { | ||
return '' as any; | ||
}; | ||
} | ||
==== tests/cases/compiler/Api.ts (3 errors) ==== | ||
import { HttpClient } from "./http-client"; | ||
|
||
export class Api<SecurityDataType = unknown> { | ||
constructor(private http: HttpClient<SecurityDataType>) { } | ||
|
||
abc1 = () => this.http.request(); | ||
~~~~ | ||
!!! error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. | ||
abc2 = () => this.http.request(); | ||
~~~~ | ||
!!! error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. | ||
abc3 = () => this.http.request(); | ||
~~~~ | ||
!!! error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. | ||
} |
77 changes: 77 additions & 0 deletions
77
tests/baselines/reference/declarationEmitPrivatePromiseLikeInterface.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
//// [tests/cases/compiler/declarationEmitPrivatePromiseLikeInterface.ts] //// | ||
|
||
//// [http-client.ts] | ||
type TPromise<ResolveType, RejectType = any> = Omit<Promise<ResolveType>, "then" | "catch"> & { | ||
then<TResult1 = ResolveType, TResult2 = never>( | ||
onfulfilled?: ((value: ResolveType) => TResult1 | PromiseLike<TResult1>) | undefined | null, | ||
onrejected?: ((reason: RejectType) => TResult2 | PromiseLike<TResult2>) | undefined | null, | ||
): TPromise<TResult1 | TResult2, RejectType>; | ||
catch<TResult = never>( | ||
onrejected?: ((reason: RejectType) => TResult | PromiseLike<TResult>) | undefined | null, | ||
): TPromise<ResolveType | TResult, RejectType>; | ||
}; | ||
|
||
export interface HttpResponse<D extends unknown, E extends unknown = unknown> extends Response { | ||
data: D; | ||
error: E; | ||
} | ||
|
||
export class HttpClient<SecurityDataType = unknown> { | ||
public request = <T = any, E = any>(): TPromise<HttpResponse<T, E>> => { | ||
return '' as any; | ||
}; | ||
} | ||
//// [Api.ts] | ||
import { HttpClient } from "./http-client"; | ||
|
||
export class Api<SecurityDataType = unknown> { | ||
constructor(private http: HttpClient<SecurityDataType>) { } | ||
|
||
abc1 = () => this.http.request(); | ||
abc2 = () => this.http.request(); | ||
abc3 = () => this.http.request(); | ||
} | ||
|
||
//// [http-client.js] | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.HttpClient = void 0; | ||
var HttpClient = /** @class */ (function () { | ||
function HttpClient() { | ||
this.request = function () { | ||
return ''; | ||
}; | ||
} | ||
return HttpClient; | ||
}()); | ||
exports.HttpClient = HttpClient; | ||
//// [Api.js] | ||
"use strict"; | ||
exports.__esModule = true; | ||
exports.Api = void 0; | ||
var Api = /** @class */ (function () { | ||
function Api(http) { | ||
var _this = this; | ||
this.http = http; | ||
this.abc1 = function () { return _this.http.request(); }; | ||
this.abc2 = function () { return _this.http.request(); }; | ||
this.abc3 = function () { return _this.http.request(); }; | ||
} | ||
return Api; | ||
}()); | ||
exports.Api = Api; | ||
|
||
|
||
//// [http-client.d.ts] | ||
declare type TPromise<ResolveType, RejectType = any> = Omit<Promise<ResolveType>, "then" | "catch"> & { | ||
then<TResult1 = ResolveType, TResult2 = never>(onfulfilled?: ((value: ResolveType) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: RejectType) => TResult2 | PromiseLike<TResult2>) | undefined | null): TPromise<TResult1 | TResult2, RejectType>; | ||
catch<TResult = never>(onrejected?: ((reason: RejectType) => TResult | PromiseLike<TResult>) | undefined | null): TPromise<ResolveType | TResult, RejectType>; | ||
}; | ||
export interface HttpResponse<D extends unknown, E extends unknown = unknown> extends Response { | ||
data: D; | ||
error: E; | ||
} | ||
export declare class HttpClient<SecurityDataType = unknown> { | ||
request: <T = any, E = any>() => TPromise<HttpResponse<T, E>, any>; | ||
} | ||
export {}; |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Declaration emit for this test still takes 5s on my machine.
getPreEmitDiagnostics
invokes declaration emit to get declaration emit errors (for historical reasons they've been considered "preEmit" errors), meaning declaration emit had to run twice, so 10s. Single-threaded, this was fine, but in high resource contention scenarios (ie,runtests-parallel
) this was long enough to stretch to 40s and timeout. So I added an opt-out case to the preEmit/preEmit-after-emit error consistency check to keep this test runtime low (so it could pass without a timeout when running in parallel, and probably on CI).