Skip to content
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

Merged
merged 19 commits into from
Jun 16, 2016

Conversation

zhengbli
Copy link
Contributor

@zhengbli zhengbli commented Mar 11, 2016

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

@@ -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.": {
Copy link
Member

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

Copy link
Contributor Author

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."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it :-)

@billti
Copy link
Member

billti commented Mar 13, 2016

Added some comments. Note this pull request should be against release-1.8 also if VSCode wants it for their release, not against master. Thanks!

@@ -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;
Copy link
Contributor Author

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

zhengbli added a commit to zhengbli/TypeScript that referenced this pull request Mar 14, 2016
{
name: "disableSizeLimit",
type: "boolean",
description: Diagnostics.Disable_the_upper_limit_for_the_total_file_size_of_a_project
Copy link
Contributor

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.

@zhengbli
Copy link
Contributor Author

@billti @mhegazy @vladima Please review the updated code, I'll try to merge into 1.8 once this PR got thumbs up. Thanks!

zhengbli added a commit to zhengbli/TypeScript that referenced this pull request Mar 15, 2016
@@ -1452,6 +1454,27 @@ namespace ts {
return file;
}

if (!options.disableSizeLimit) {
if (programSizeForNonTsFiles === -1) {
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit. return undefined;

zhengbli added a commit that referenced this pull request Mar 15, 2016
@zhengbli zhengbli force-pushed the fixLargeProjectTry2 branch from 36b8172 to cb46f16 Compare March 18, 2016 02:58
@zhengbli
Copy link
Contributor Author

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);
Copy link
Member

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 😄

@billti
Copy link
Member

billti commented Mar 18, 2016

Looks good at first read. We should add the same logic on the VS host side also to improve Salsa experience there.

@zhengbli
Copy link
Contributor Author

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)) {
Copy link
Contributor

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.

zhengbli added 3 commits June 9, 2016 14:58
… 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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this already handled by @riknoll in #8841. can we make sure we are doing one approach for both PRs.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

@mhegazy
Copy link
Contributor

mhegazy commented Jun 9, 2016

We need a unit test for this, now that we have unit tests :)

@mhegazy
Copy link
Contributor

mhegazy commented Jun 9, 2016

@vladima any comments?

@zhengbli zhengbli force-pushed the fixLargeProjectTry2 branch from c0e232e to e41b10b Compare June 10, 2016 09:06
@zhengbli
Copy link
Contributor Author

@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) {
Copy link
Contributor

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.

@mhegazy
Copy link
Contributor

mhegazy commented Jun 15, 2016

👍

zhengbli added 2 commits June 15, 2016 14:36
… fixLargeProjectTry2

# Conflicts:
#	src/compiler/program.ts
#	tests/cases/unittests/tsserverProjectSystem.ts
@zhengbli zhengbli force-pushed the fixLargeProjectTry2 branch from c6f9e25 to 550d912 Compare June 15, 2016 23:52
@zhengbli zhengbli merged commit 95ae809 into microsoft:master Jun 16, 2016
@zhengbli zhengbli deleted the fixLargeProjectTry2 branch June 16, 2016 00:31
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JS error highlighting stops working in some cases tsserver crashes with large projects
4 participants