Skip to content

Perf improvements part 3 - #1510

Merged
jonsequitur merged 26 commits into
dotnet:mainfrom
adamsitnik:perfImprovements3
Dec 17, 2021
Merged

jonsequitur merged 26 commits into
dotnet:mainfrom
adamsitnik:perfImprovements3

Conversation

@adamsitnik

@adamsitnik adamsitnik commented Dec 10, 2021 •

Copy link
Copy Markdown
Member

@jonsequitur I am about to start my weekend now, so I am just opening the PR and providing benchmark results. On Monday I am going to describe why I've changed all of these things.

Method Args Mean before Mean after Allocated before Allocated after
DefaultsSync String[0] 38.892 us 30.004 us 25,611 B 14,010 B
DefaultsAsync String[0] 38.594 us 29.371 us 25,611 B 14,010 B
MinimalSync String[0] 6.905 us 3.366 us 12,201 B 6,753 B
MinimalAsync String[0] 7.084 us 3.453 us 12,201 B 6,753 B
DefaultsSync String[4] 44.543 us 33.569 us 30,016 B 17,432 B
DefaultsAsync String[4] 45.152 us 33.727 us 30,016 B 17,432 B
MinimalSync String[4] 10.513 us 5.739 us 16,608 B 10,176 B
MinimalAsync String[4] 10.398 us 5.888 us 16,608 B 10,176 B

@jonsequitur

jonsequitur commented Dec 10, 2021 •

Copy link
Copy Markdown
Contributor

This is a great improvement! Some of these changes (using readonly struct for some types) were already on my to-do list so thank you for doing this. I would love to merge this if you feel it's ready.

One change that I'm wondering about is the addition of the IMatchable interface to support name-based matching. I'd like to investigate an alternate approach.

We've recently moved the name-based binding out into a separate package (System.CommandLine.NamingConventionBinder). The name matching functionality is partly there to support that but also to support validation of the parser, e.g. detect naming collisions that would make a command line unparseable.

With that in mind, can you think of an approach that avoids introducing an interface?

On a possibly related note, we've also discussed removing ICommand, IArgument, and IOption. They were introduced when we made the parser mutable in order to avoid writing code to gently discourage mutating symbols once the parser is constructed. I don't believe they add value, though, and we don't expect people to implement them.

# Conflicts:
#	src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt
#	src/System.CommandLine/ISymbol.cs
#	src/System.CommandLine/Invocation/SuggestDirectiveResult.cs
#	src/System.CommandLine/Parsing/ParseResultExtensions.cs
@adamsitnik

Copy link
Copy Markdown
Member Author

can you think of an approach that avoids introducing an interface?

Sure! I'll see what I can do and get back to you.

On a possibly related note, we've also discussed removing ICommand, IArgument, and IOption

I am in favor of removing every abstraction that is implemented by a single type and|or is never implemented by the users. 👍

… Commands and Options

remove WasBundled as it was not used anywhere
remove AliasedSet, don't verify aliases at model creation time

remove ContainsAlias and GetByAlias as they are not needed since Token got extended with Symbol
# Conflicts:
#	src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt
#	src/System.CommandLine/Argument.cs
#	src/System.CommandLine/Help/HelpBuilder.cs
#	src/System.CommandLine/Parsing/StringExtensions.cs
#	src/System.CommandLine/Parsing/SymbolResult.cs
Comment thread src/System.CommandLine/Command.cs Outdated
{
if (ReferenceEquals(this, command))
{
throw new ArgumentException("Parent can't be it's own child.");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would suggest a different exception type.

Also, minor correction:

Suggested change
throw new ArgumentException("Parent can't be it's own child.");
throw new ArgumentException("Parent can't be its own child.");

Comment thread src/System.CommandLine/Command.cs Outdated
/// </summary>
/// <remarks>Due to the performance impact of this method, it's recommended to create
/// a Unit Test that calls this method to verify the RootCommand of every application.</remarks>
public void Validate()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's discuss naming to make it clearer this is not about input validation.

Comment thread src/System.CommandLine/Option.cs Resolved
Comment thread src/System.CommandLine/Symbol.cs Resolved
* make Matches internal
* make IsGlobal internal
* make SymbolResult.Children readonly
* add comment about complexity and perf
* move Command.Validate to CommandLineConfiguration, delete the tests for now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants