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

Minor Performance Optimization by Reducing Calls to AppDomain.CurrentDomain.FriendlyName #8567

Merged
merged 2 commits into from
Sep 19, 2024

Conversation

lindexi
Copy link
Member

@lindexi lindexi commented Dec 18, 2023

Description

I have optimized the performance by reducing the number of times AppDomain.CurrentDomain.FriendlyName property is accessed. Accessing the FriendlyName property is not cheap and results in some additional performance overhead. By assigning it to a local variable first, I have managed to reduce multiple property accesses, thereby slightly improving performance without altering the existing logic.

    public sealed partial class AppDomain : MarshalByRefObject
    {
        public string FriendlyName
        {
            get
            {
                Assembly? assembly = Assembly.GetEntryAssembly();
                return assembly != null ? assembly.GetName().Name! : "DefaultDomain";
            }
        }
   }

See https://github.com/dotnet/runtime/blob/222d4c5df0b63edb4dbb75771c6e0f8c1315746e/src/libraries/System.Private.CoreLib/src/System/AppDomain.cs#L65-L72

Customer Impact

Minor Performance Optimization

Regression

None.

Testing

Just CI.

Risk

Very Low?

Microsoft Reviewers: Open in CodeFlow

…ain.FriendlyName`

I have optimized the performance by reducing the number of times `AppDomain.CurrentDomain.FriendlyName` property is accessed. Accessing the FriendlyName property is not cheap and results in some additional performance overhead. By assigning it to a local variable first, I have managed to reduce multiple property accesses, thereby slightly improving performance without altering the existing logic.

```
    public sealed partial class AppDomain : MarshalByRefObject
    {
        public string FriendlyName
        {
            get
            {
                Assembly? assembly = Assembly.GetEntryAssembly();
                return assembly != null ? assembly.GetName().Name! : "DefaultDomain";
            }
        }
   }
```
@lindexi lindexi requested a review from a team as a code owner December 18, 2023 12:22
@ghost ghost assigned lindexi Dec 18, 2023
@ghost ghost added the PR metadata: Label to tag PRs, to facilitate with triage label Dec 18, 2023
@ghost ghost requested review from dipeshmsft and singhashish-wpf December 18, 2023 12:22
@ghost ghost added the Community Contribution A label for all community Contributions label Dec 18, 2023
@dipeshmsft
Copy link
Member

LGTM. I ran the benchmark and there's around 1.6 ms on one invocation of the HwndWrapper

@lindexi lindexi requested a review from a team as a code owner September 19, 2024 01:52
@dipeshmsft dipeshmsft merged commit f19253d into dotnet:main Sep 19, 2024
8 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Oct 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Community Contribution A label for all community Contributions PR metadata: Label to tag PRs, to facilitate with triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants