-
-
Notifications
You must be signed in to change notification settings - Fork 138
Working on adding xml whitespace ignore. #1794
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
Draft
belav
wants to merge
12
commits into
main
Choose a base branch
from
xml-ignore-whitespace
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
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
…#1703) Semi reverts #1572 which overwrote #1485, I assume this was accidental. I noticed that you prefer explicit `Enumerable.Any` usage, should I convert this PR to use `ListExtensions.Any`? ## Benchmarks Saves around 15% of memory usage ### Before | Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated | |------------------------------ |---------:|--------:|--------:|----------:|----------:|----------:| | Default_CodeFormatter_Tests | 128.0 ms | 2.44 ms | 3.43 ms | 3000.0000 | 1000.0000 | 34.57 MB | | Default_CodeFormatter_Complex | 260.3 ms | 5.11 ms | 7.17 ms | 5000.0000 | 2000.0000 | 53.05 MB | ### After | Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated | |------------------------------ |---------:|--------:|---------:|----------:|----------:|----------:| | Default_CodeFormatter_Tests | 126.0 ms | 2.27 ms | 5.45 ms | 2000.0000 | 1000.0000 | 28.02 MB | | Default_CodeFormatter_Complex | 245.2 ms | 4.63 ms | 10.44 ms | 4000.0000 | 2000.0000 | 43.88 MB | Co-authored-by: Bela VanderVoort <twobitbela@gmail.com>
) Add check for if `modifiers` are `Doc.Null` to avoid allocating a `Concat` and `Doc[]` ### Benchmarks (timing is inaccurate) #### Before | Method | Mean | Error | StdDev | Median | Gen0 | Gen1 | Allocated | |------------------------------ |---------:|--------:|--------:|---------:|----------:|----------:|----------:| | Default_CodeFormatter_Tests | 131.9 ms | 3.30 ms | 8.86 ms | 128.0 ms | 3000.0000 | 1000.0000 | 34.57 MB | | Default_CodeFormatter_Complex | 261.3 ms | 5.16 ms | 4.03 ms | 261.3 ms | 5000.0000 | 2000.0000 | 53.03 MB | #### After | Method | Mean | Error | StdDev | Median | Gen0 | Gen1 | Allocated | |------------------------------ |---------:|---------:|---------:|---------:|----------:|----------:|----------:| | Default_CodeFormatter_Tests | 189.5 ms | 10.25 ms | 28.05 ms | 195.6 ms | 3000.0000 | 1000.0000 | 34.31 MB | | Default_CodeFormatter_Complex | 264.2 ms | 5.27 ms | 13.97 ms | 260.0 ms | 5000.0000 | 2000.0000 | 52.31 MB | Co-authored-by: Bela VanderVoort <twobitbela@gmail.com>
Not sure if more changes might help here, perhaps calling `docsStack.Push(TraverseDocOnExitStackMarker);` later and adding an `else` clause might help, that or using a goto. Might be easier to measure an improvement once other changes were made. Did wonder if `ValueListBuilder` will help due to faster `Push` and `Pop`. Co-authored-by: Bela VanderVoort <twobitbela@gmail.com>
Most `result` Lists are always just under `3 * members.Count`, small change but simple 🤷 ### Benchmarks (timing is inaccurate should be the same) #### Before | Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated | |------------------------------ |---------:|--------:|--------:|----------:|----------:|----------:| | Default_CodeFormatter_Tests | 133.0 ms | 2.56 ms | 2.84 ms | 3000.0000 | 1000.0000 | 34.58 MB | | Default_CodeFormatter_Complex | 271.5 ms | 5.40 ms | 7.92 ms | 5000.0000 | 2000.0000 | 52.95 MB | #### After | Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated | |------------------------------ |---------:|--------:|--------:|----------:|----------:|----------:| | Default_CodeFormatter_Tests | 132.4 ms | 2.64 ms | 3.87 ms | 3000.0000 | 1000.0000 | 34.56 MB | | Default_CodeFormatter_Complex | 268.2 ms | 4.92 ms | 4.60 ms | 5000.0000 | 2000.0000 | 52.78 MB | Co-authored-by: Bela VanderVoort <twobitbela@gmail.com>
It appears that `SyntaxNodeComparer` is run after a file is formated, optimisation here may be impactful - Prevent null `Func<T, T, Result>` allocations (still seeing some in the profiler, no idea how to sotp this) - Prevent boxing of `SyntaxTokenList`, `SyntaxNodeOrTokenList` - Use `OrderBy.ToArray` instead of `OrderBy.ToList` - Create `AllSeparatorsButLast` to prevent boxing `SeparatedSyntaxList<SyntaxNode>` and `IEnumerable` creation I have some other idea, but I'm focusing on the unhappy path right now. ### Benchmark (comparing `complexCode`) #### Before | Method | Mean | Error | StdDev | Gen0 | Gen1 | Gen2 | Allocated | |--------------------------- |---------:|--------:|--------:|----------:|----------:|----------:|----------:| | Default_SyntaxNodeComparer | 229.1 ms | 4.55 ms | 7.60 ms | 5000.0000 | 3000.0000 | 1000.0000 | 40.53 MB | #### After | Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated | |--------------------------- |---------:|--------:|--------:|----------:|----------:|----------:| | Default_SyntaxNodeComparer | 187.4 ms | 3.51 ms | 7.64 ms | 3000.0000 | 1000.0000 | 31.39 MB | Co-authored-by: Bela VanderVoort <twobitbela@gmail.com>
- Compare the old and formatted code before using `SyntaxNodeComparer` (ie new version of csharpier, no changes but hash is cache is invalidated) - Skip comparison if two `TypeDeclaration` aka (classes, struct, interfaces etc) or `MethodDeclaration` are identical - This could be done for all `SyntaxNodes` but may slow things down if most nodes have changed The CLI spends up to 30% of the time doing comparisons, with this, we can skip cases with identical source code, and only compare types/methods that have changed. The performance degradation for lots of changes (i.e. first time a project is formatted) shouldn't be that great as `CompareFullSpan` is basically a fast `SequenceEqual` and only used for type declarations and methods. Co-authored-by: Bela VanderVoort <twobitbela@gmail.com>
Repeatedly compiling regex for ignore files is a significant amount of runtime, caches the `IgnoreWithBasePath` to prevent this. See also #1776 ### Before | Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated | |---------- |---------:|---------:|---------:|----------:|----------:|----------:| | FormatCli | 955.0 ms | 17.65 ms | 29.98 ms | 9000.0000 | 1000.0000 | 81.5 MB | ### After | Method | Mean | Error | StdDev | Gen0 | Allocated | |---------- |---------:|---------:|---------:|----------:|----------:| | FormatCli | 683.5 ms | 13.61 ms | 30.17 ms | 7000.0000 | 69.33 MB | Co-authored-by: Bela VanderVoort <twobitbela@gmail.com>
This is just adding the options that will eventually be used by the new xml whitespace handling code.
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.
No description provided.