Skip to content

Avoid using closure in Parser.SaveError #11006

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

Merged
1 commit merged into from
Nov 8, 2019
Merged

Conversation

daxian-dbw
Copy link
Member

@daxian-dbw daxian-dbw commented Nov 7, 2019

PR Summary

Avoid using closure in Parser.SaveError.

Context

Generally, Parser.SaveError shouldn't be called too frequently in production, because the script running in production should have been correct and generate no parsing error.
However, I saw the following call stack in Azure Profiler Viewer for PowerShell Gallery-Prod service:

image

Parser.SaveError takes about 43.56% of the CPU activities in the web server process w3wp.exe, and the call originates from NuGetGallery.Views.ScriptParsingAndHighlighting!Parse

image

Given the finding, I took a look at the implementation of Parser.SaveError and notice that it's using closure and LINQ unnecessarily. Especially, the closure use will cause allocation every time this method is called.
As for why PowerShellGallery triggers so many parsing errors, it's because it's parsing non-powershell files using powershell parser, which is wrong and will be fixed.

PR Checklist

@daxian-dbw daxian-dbw added the CL-Performance Indicates that a PR should be marked as a performance improvement in the Change Log label Nov 7, 2019
@iSazonov iSazonov added this to the 7.0.0-preview.6 milestone Nov 7, 2019
@adityapatwardhan
Copy link
Member

@PoshChan Please remind me in 4 hours.

@adityapatwardhan adityapatwardhan added the AutoMerge informs the bot to automerge the PR label Nov 7, 2019
@ghost
Copy link

ghost commented Nov 7, 2019

Hello @adityapatwardhan!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

Do note that I've been instructed to only help merge pull requests of this repository that have been opened for at least 24 hours, a condition that will be fulfilled in about 4 hours 7 minutes. No worries though, I will be back when the time is right! 😉

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@PoshChan
Copy link
Collaborator

PoshChan commented Nov 8, 2019

@adityapatwardhan, this is the reminder you requested 4 hours. ago

@ghost ghost merged commit fff137e into PowerShell:master Nov 8, 2019
@daxian-dbw daxian-dbw deleted the saveerror branch November 8, 2019 01:00
@ghost
Copy link

ghost commented Nov 21, 2019

🎉v7.0.0-preview.6 has been released which incorporates this pull request.:tada:

Handy links:

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AutoMerge informs the bot to automerge the PR CL-Performance Indicates that a PR should be marked as a performance improvement in the Change Log
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants