-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add upper limit for the program size to prevent tsserver from crashing #7486
Conversation
@@ -2824,5 +2824,9 @@ | |||
"Unknown typing option '{0}'.": { | |||
"category": "Error", | |||
"code": 17010 | |||
}, | |||
"Too many javascript files in the project. Consider add to the `exclude` list in the config file.": { |
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.
Grammar: "Consider adding to...". Or perhaps just reworded as "Use the 'exclude' setting in project configuration to limit included source folders".
Note: Do we predicate this message on the user not having listed the files to compile? If we are not scanning directories anyway (i.e. there is a list of files given), then this message would be misleading (as exclude
can't be specified - at least until the globbing change comes in).
Also, capitalize as "JavaScript", not "javascript", and don't use backticks. This isn't markdown :-p
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.
I agree that we should mention both cases, with or without the "exclude" list. Does the following sound better:
"Too many JavaScript files in the project. Use an exact 'files' list, or use the 'exclude' setting in project configuration to limit included source folders."
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.
I like it :-)
Added some comments. Note this pull request should be against |
@@ -2866,4 +2870,6 @@ namespace ts { | |||
export function isParameterPropertyDeclaration(node: ParameterDeclaration): boolean { | |||
return node.flags & NodeFlags.AccessibilityModifier && node.parent.kind === SyntaxKind.Constructor && isClassLike(node.parent.parent); | |||
} | |||
|
|||
export const maxProgramSize = 20 * 1024 * 1024; |
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.
Changed the upper limit from 35M to 20M, as on my machine even 35M would still run out of memory
{ | ||
name: "disableSizeLimit", | ||
type: "boolean", | ||
description: Diagnostics.Disable_the_upper_limit_for_the_total_file_size_of_a_project |
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.
remove the description, so that it does not show in the help.
@@ -1452,6 +1454,27 @@ namespace ts { | |||
return file; | |||
} | |||
|
|||
if (!options.disableSizeLimit) { | |||
if (programSizeForNonTsFiles === -1) { | |||
return; |
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.
nit. return undefined;
… fixLargeProjectTry2 # Conflicts: # src/compiler/types.ts
… fixLargeProjectTry2
36b8172
to
cb46f16
Compare
With the new updates, the response time for the first "ProjectInfo" request was reduced to around 5s from 40+s for the repro sample at #7444 originally, due to avoiding creating programs for the project and speeding up in the file traversing process. |
// Get files of supported extensions in their order of resolution | ||
for (const extension of supportedExtensions) { | ||
const filesInDirWithExtension = host.readDirectory(basePath, extension, exclude); |
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.
We were re-reading the directory for every file extension in the list? Crazy!! Good find 😄
Looks good at first read. We should add the same logic on the VS host side also to improve Salsa experience there. |
Ping @mhegazy |
… fixLargeProjectTry2 # Conflicts: # src/compiler/commandLineParser.ts # src/compiler/types.ts
… fixLargeProjectTry2 # Conflicts: # src/compiler/sys.ts
@@ -1463,6 +1477,25 @@ namespace ts { | |||
} | |||
}); | |||
|
|||
if (!options.disableSizeLimit && file && file.text && !hasTypeScriptFileExtension(file.fileName)) { |
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.
looks like we do not need this in the program building, since we are doing it in the server.
… fixLargeProjectTry2 # Conflicts: # src/compiler/commandLineParser.ts # src/compiler/program.ts # src/compiler/sys.ts # src/compiler/types.ts # src/server/editorServices.ts # src/server/session.ts
@@ -723,10 +727,22 @@ namespace ts { | |||
const supportedExtensions = getSupportedExtensions(options); | |||
Debug.assert(indexOf(supportedExtensions, ".ts") < indexOf(supportedExtensions, ".d.ts"), "Changed priority of extensions to pick"); | |||
|
|||
const potentialFiles: string[] = []; | |||
if (host.readDirectoryWithMultipleExtensions) { | |||
addRange(potentialFiles, host.readDirectoryWithMultipleExtensions(basePath, supportedExtensions, exclude)); |
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.
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.
possibly split this in a separate PR.
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.
Sure.
We need a unit test for this, now that we have unit tests :) |
@vladima any comments? |
c0e232e
to
e41b10b
Compare
@mhegazy updated with a test |
@@ -1299,7 +1416,43 @@ namespace ts.server { | |||
return errors; | |||
} | |||
else { | |||
const oldFileNames = project.compilerService.host.roots.map(info => info.fileName); | |||
if (this.exceedTotalNonTsFileSizeLimit(projectOptions.files) && projectOptions.compilerOptions && !projectOptions.compilerOptions.disableSizeLimit) { |
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.
move this !projectOptions.compilerOptions.disableSizeLimit
to the beginning.
👍 |
… fixLargeProjectTry2 # Conflicts: # src/compiler/program.ts # tests/cases/unittests/tsserverProjectSystem.ts
c6f9e25
to
550d912
Compare
Fixes #7444
For experimental purpose, the upper limit was set to 35 Mb (as suggested in #7444 (comment)), which might be changed to a better value after further tests.
Per our discussion in #7444, the next step is to add a compiler switch (something like disableSizeLimit) to disable this check for a project. Though I will do that after the current size-checking logic was reviewed.
Edit: also fix #8212