Skip to content

Minor performance improvements for runspace initialization - #10569

Merged
Dongbo Wang (daxian-dbw) merged 2 commits into
PowerShell:masterfrom
iSazonov:perf-startup-read-snapins
Oct 15, 2019
Merged

Dongbo Wang (daxian-dbw) merged 2 commits into
PowerShell:masterfrom
iSazonov:perf-startup-read-snapins

Conversation

@iSazonov

@iSazonov Ilya (iSazonov) commented Sep 18, 2019 •

Copy link
Copy Markdown
Collaborator

PR Summary

Comments says that the code was optimized in Windows PowerShell but there is still room for improvements that is important for scenarios actively using runspaces and startup.

  1. Remove check that file exist.
    The code came from Windows PowerShell but now all the standard dlls is placed in $PSHome and we have no need to search them in other paths by the dll name.
    image

  2. Remove some obvious allocations

  • Assembly.GetName() allocates - put it in temp variable.
  • Move Version.ToString() out of the cycle.

PR Context

PR Checklist

@iSazonov Ilya (iSazonov) added the CL-Performance Indicates that a PR should be marked as a performance improvement in the Change Log label Sep 18, 2019
@iSazonov Ilya (iSazonov) added this to the 7.0.0-preview.5 milestone Sep 18, 2019

@daxian-dbw Dongbo Wang (daxian-dbw) left a comment

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.

Perf win ~2.3%

This comment is not accurate. This code path is hit 4 or 5 times at most when Runspace opens. There are many other places checks for file existence, such as in PowerShellConfig when reading the config json file. So removing this check won't eliminate all FileSystem.FileExist calls.

@daxian-dbw

Dongbo Wang (daxian-dbw) commented Oct 10, 2019 •

Copy link
Copy Markdown
Member

Can you update your PR description to not say a 2.3% perf win?
Also, when having a screenshot of profiling result, I suggest to describe what was profiled (e.g. the command executed by PerfView->Run), so there is more context.

@iSazonov

Copy link
Copy Markdown
Collaborator Author

PerfView shows follow code paths:
image

So expected win is up to 1.8%.

I tested Runspace.Open() if I remember right three weeks later :-)

@daxian-dbw

Copy link
Copy Markdown
Member

It's still not accurate as there may be other calls to File.Exist within the code paths hit by RunspaceFactory.CreateRunspace. I suggest to remove the Perf Win part in the PR description.

@iSazonov

Copy link
Copy Markdown
Collaborator Author

Done.

@iSazonov

Copy link
Copy Markdown
Collaborator Author

Dongbo Wang (@daxian-dbw) Could you please merge?

@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit c76e122 into PowerShell:master Oct 15, 2019
@daxian-dbw

Copy link
Copy Markdown
Member

Ilya (@iSazonov) Sorry I forgot this :)

@iSazonov
Ilya (iSazonov) deleted the perf-startup-read-snapins branch October 16, 2019 03:01
@ghost

Copy link
Copy Markdown

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

Handy links:

Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants