Skip to content

Conversation

@adamsitnik
Copy link
Member

fixes #1963

…an be used don't let types derived from `Option<T>` to override Argment property, require them to always pass it to the `ctor` so `_argument` and `Argument` always point to the same object inline Argument.None to reduce the number of methods compiled by the JIT at startup (it was used only in 2 places so it should be OK)
_argument = argument;
}

internal sealed override Argument Argument => _argument;
Copy link
Member Author

Choose a reason for hiding this comment

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

By making this property sealed we enforce all Option<T> derived types to always pass an instance of Argument<T> to the ctor. By doing that, we are always sure that _argument (the field) and Argument (the property) always refer to the same instance of an object. In the past it was not always a thing?

Another benefit is that when the derived types are being created, only one Argument<T> is being allocated.

Copy link
Member

@jozkee jozkee left a comment

Choose a reason for hiding this comment

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

Otherwise, LGTM. Sorry for breaking the SDK 😅.


public HelpOption(string[] aliases, Func<LocalizationResources> getLocalizationResources)
: base(aliases)
: base(aliases, null, new Argument<bool> { Arity = ArgumentArity.Zero })
Copy link
Member

Choose a reason for hiding this comment

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

Could new Argument<bool> { Arity = ArgumentArity.Zero } be in a static and be re-used here and on VerisonOption?

Copy link
Member Author

Choose a reason for hiding this comment

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

IIRC I've tried it in the past (when I was working on SCL perf) and it was impossible as some of the methods were allowing for mutation, but I am not 100% sure if this is the case now.

Once we are done with API-redesign and re-layering we are going to profile the startup scenario again and if it pops up, try to cache it. But initializing static fields also has a cost, so this will have to be carefully verified.

@adamsitnik adamsitnik merged commit 8374d5f into dotnet:main Nov 14, 2022
@adamsitnik adamsitnik deleted the moveExtensionsToGenericTypes branch November 14, 2022 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants