Skip to content

Add cache for GetApplicationBase - #3969

Merged
Dongbo Wang (daxian-dbw) merged 3 commits into
PowerShell:masterfrom
iSazonov:cache-for-getapplicationbase
Jun 20, 2017
Merged

Add cache for GetApplicationBase#3969
Dongbo Wang (daxian-dbw) merged 3 commits into
PowerShell:masterfrom
iSazonov:cache-for-getapplicationbase

Conversation

@iSazonov

@iSazonov Ilya (iSazonov) commented Jun 8, 2017

Copy link
Copy Markdown
Collaborator

Motivation

We call Utils.GetApplicationBase() multiple times at startup and later so we need cache the one to exclude a reflection.

Fix

  1. Add a static getter-only property named DefaultPowerShellAppBase in Utils.cs.
  2. Refactor code to directly use cached value.

Additional considerations

Code that uses a ShellId from Context has not been changed, although it is only associated with the Windows PowerShell (FullCLR).

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.

How about having an internal static property named DefaultPowerShellAppBase like this:

internal static string DefaultPowerShellAppBase { get; } = GetApplicationBase(DefaultPowerShellShellID);

And then use this get-only property in places where GetApplicationBase(DefaultPowerShellShellID) is used.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch!

Done.

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.

With that getter-only property, you won't need this method.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

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.

With that getter-only property, you won't need to add this.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

@daxian-dbw

Copy link
Copy Markdown
Member

Ilya (@iSazonov) Sorry about the late review 😦

Clean up code to use cached value s_GetApplicationBaseDefaultPowerShell
@iSazonov
Ilya (iSazonov) force-pushed the cache-for-getapplicationbase branch from debbae4 to b06e43a Compare June 20, 2017 06:34
if (DefaultPowerShellAppBase != null)
{
return DefaultPowerShellAppBase;
}

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.

This is a bit confusing -- looks like a recursion would happen even though it's not. I suggest removing this if block.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit 598cebf into PowerShell:master Jun 20, 2017
@iSazonov
Ilya (iSazonov) deleted the cache-for-getapplicationbase branch June 21, 2017 05:34
@iSazonov

Copy link
Copy Markdown
Collaborator Author

Dongbo Wang (@daxian-dbw) Thanks for the code review!

Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj/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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants