Skip to content

Log top 5 largest files when TS language service is disabling.#19315

Merged
mhegazy merged 8 commits into
microsoft:masterfrom
unional:log-top5-largest
Oct 31, 2017
Merged

Log top 5 largest files when TS language service is disabling.#19315
mhegazy merged 8 commits into
microsoft:masterfrom
unional:log-top5-largest

Conversation

@unional
Copy link
Copy Markdown
Contributor

@unional unional commented Oct 18, 2017

This PR mitigates an issue on vscode: microsoft/vscode#35549

It will now log the top 5 largest files loaded.
Suggestion on how to format the message is welcome.

There is no test added 😞 because I can't find a way to test this private method, and also stubbing the logger to validate the output.

@unional
Copy link
Copy Markdown
Contributor Author

unional commented Oct 18, 2017

If you find sorting and managing the top5 list is too time-consuming, maybe we can just report the largest file.

This second pass seemingly should be avoid. Bug there.
@unional
Copy link
Copy Markdown
Contributor Author

unional commented Oct 19, 2017

I notice this method is being called twice on the same project. So it seems that it double counted the file size.

microsoft/vscode#35549 (comment)

@unional unional changed the title Log top 5 largest files for TS language service disabling. Log top 5 largest files when TS language service is disabling. Oct 19, 2017
Comment thread src/server/editorServices.ts Outdated
this.projectToSizeMap.forEach(val => (availableSpace -= (val || 0)));

let totalNonTsFileSize = 0;
let top5LargestFiles = [] as { name: string, size: number }[];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use an annotation, not a type assertion.

@DanielRosenwasser
Copy link
Copy Markdown
Member

#19326 is probably the right issue to track this.

@DanielRosenwasser
Copy link
Copy Markdown
Member

DanielRosenwasser commented Oct 20, 2017

I think that in the error case, you should just sort the list of all files and slice off the top 5 instead of inserting the logic into the loop.

@unional
Copy link
Copy Markdown
Contributor Author

unional commented Oct 20, 2017

I think that in the error case, you should just sort the list of all files and slice off the top 5 instead of inserting the logic into the loop.

Sure, can do that too. But in order to do that, I have to use { name: string, size: number}[n] where n is number of files.
Just more memory to GC.

@unional
Copy link
Copy Markdown
Contributor Author

unional commented Oct 20, 2017

Any comment on the log message?

@unional
Copy link
Copy Markdown
Contributor Author

unional commented Oct 20, 2017

In the last commit, I use logExceedLimit.call(this) because I don't want to declare const logExceedLimit = () => { ... } in front of the method.

Error handling and logging code should not obstruct main code path.

An alternative is to make it a pure function.

Comment thread src/server/editorServices.ts Outdated
}

const size = this.host.getFileSize(name);
totalNonTsFileSize += size;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do you need to compute this again?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

consider:

fileNames
   .map(f => hasTypeScriptFileExtension(name) ? 0 : { name, size: host.getFileSize(name) })
   .sort((a, b) => b.size - a.size)
   .slice(0,5)
   .map(f => `${f.name} (${f.size})`)
   .join(",")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's a good idea, but I'll separate formatting from the chain.

Comment thread src/server/editorServices.ts Outdated
totalNonTsFileSize += this.host.getFileSize(fileName);

if (totalNonTsFileSize > maxProgramSizeForNonTsFiles) {
logExceedLimit.call(this);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we need top 5? or can we jsut log the largest so far? if so, we can keep the largest file in a local.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

W can do that too. I initially do top 5 just to get more information so I can exclude/fix multiple files at the same time.

@unional
Copy link
Copy Markdown
Contributor Author

unional commented Oct 31, 2017

do you need to compute this again?

I change to passing that value in. However, it is not an accurate number because in the main loop it exits once totalNonTsFileSize > maxProgramSizeForNonTsFiles.

Comment thread src/server/editorServices.ts Outdated
this.projectToSizeMap.set(name, totalNonTsFileSize);
return false;

function logExceedLimit(this: ProjectService, totalNonTsFileSize: number) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why do you need the this here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

just pass in the logger/host, or make the function return a string.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, that would be even better.

@mhegazy mhegazy merged commit 53ad019 into microsoft:master Oct 31, 2017
@unional unional deleted the log-top5-largest branch October 31, 2017 23:41
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 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.

3 participants