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

Make PlatformDetection.IsInHelix lazy #68445

Merged
merged 2 commits into from
Apr 24, 2022
Merged

Conversation

danmoseley
Copy link
Member

No description provided.

@ghost
Copy link

ghost commented Apr 23, 2022

Tagging subscribers to this area: @dotnet/area-infrastructure-libraries
See info in area-owners.md if you want to be subscribed.

Issue Details

null

Author: danmoseley
Assignees: -
Labels:

area-Infrastructure-libraries

Milestone: -

@danmoseley danmoseley merged commit 46464bd into dotnet:main Apr 24, 2022
@danmoseley danmoseley deleted the helix.lazy branch April 24, 2022 00:27
@@ -23,7 +23,8 @@ public static partial class PlatformDetection
// do it in a way that failures don't cascade.
//

public static readonly bool IsInHelix = Environment.GetEnvironmentVariables().Keys.Cast<string>().Where(key => key.StartsWith("HELIX")).Any();
private static Lazy<bool> s_IsInHelix => new Lazy<bool>(() => Environment.GetEnvironmentVariables().Keys.Cast<string>().Any(key => key.StartsWith("HELIX")));
Copy link

Choose a reason for hiding this comment

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

Think you want a field here, i.e. private static Lazy<bool> s_IsInHelix = ...

s_IsInHelix is creating a new Lazy for each invocation of the getter, so there is no caching happening here.

Copy link
Member

Choose a reason for hiding this comment

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

Good catch. We have the same problem in number of places actually.

#68473 has the fix

@ghost ghost locked as resolved and limited conversation to collaborators May 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants