Perf improvements part 6: startup time#1654
Merged
jonsequitur merged 19 commits intodotnet:mainfrom Mar 1, 2022
Merged
Conversation
…st common scenarios
… methods for it. -3ms for startup!
…vided (0.4 ms of JIT time)
…ple (struct). -4 JIT compilaitons
…educe the number of compilations and type loading
… time ArgumentConverter was used, no matter if we wanted to create a list or not)
# Conflicts: # src/System.CommandLine/Binding/ArgumentConverter.cs
jonsequitur
reviewed
Feb 23, 2022
jkotas
reviewed
Feb 23, 2022
src/System.CommandLine/Binding/ArgumentConverter.DefaultValues.cs
Outdated
Show resolved
Hide resolved
jkotas
reviewed
Feb 23, 2022
src/System.CommandLine/Binding/ArgumentConverter.DefaultValues.cs
Outdated
Show resolved
Hide resolved
jkotas
reviewed
Feb 23, 2022
| { | ||
| #if NET6_0_OR_GREATER | ||
| var ctor = (ConstructorInfo)listType.GetMemberWithSameMetadataDefinitionAs(_listCtor.Value); | ||
| ConstructorInfo? listCtor = _listCtor; |
Member
There was a problem hiding this comment.
Are there reflection-based argument conversions used with the source generator support?
Contributor
There was a problem hiding this comment.
Source generator support is still pending. The original source generator work we did was superseded by improvements we've made to support trimming.
jonsequitur
reviewed
Mar 1, 2022
| argument, | ||
| argument.Arity.MinimumNumberOfValues, | ||
| argument.Arity.MaximumNumberOfValues) is ArgumentConversionResult failed && | ||
| failed is not null) // returns null on success |
Contributor
There was a problem hiding this comment.
failed is not null check isn't needed. I think it's redundant with is ArgumentConversionResult failed which won't match if the return value of Validate is null.
jonsequitur
approved these changes
Mar 1, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The best way to review this PR is most probably to look at each commit separately. The changes belong to few categories:
ICommandHandlerwith synchronousInvokemethod: this allows to avoid the need of loading and jitting all async machinery for users who don't want to useasyncoverloads (I would imagine that most users don't need it as async should be used for potentially blocking IO operations)static Lazy<T>fields, which get jitted when given type is referenced for the firs time. I've just moved the logic to getters and it's compiled when it's used. In worst case scenario users who for some reason use multiple threads to parse command line args are going to duplicate the initialization work.structs. Every struct is of a different size and because of that, the JIT compiler needs to prepare a dedicated version of each generic collection (or other generic type that uses struct and type argument) for each unique value type. ChangingTokenfromstructtoclassreduced the number of JIT compilations reported by Perfview by 20!For the following app that mimics @jkotas example:
the total execution time measured with
Measure-Commandfor--bool true -s testarguments went down from 73 ms to 60-62 ms (Windows)