Sitelet https://github.com/belav/csharpier/pull/1703
Skip to content

perf: use overload for Any( SyntaxTriviaList to prevent allocations - #1703

Merged
belav merged 2 commits into
belav:mainfrom
TimothyMakkison:trivia_list_enumerator
Dec 25, 2025
Merged

belav merged 2 commits into
belav:mainfrom
TimothyMakkison:trivia_list_enumerator

Conversation

@TimothyMakkison

@TimothyMakkison TimothyMakkison commented Oct 11, 2025 •

Copy link
Copy Markdown
Contributor

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

@TimothyMakkison
TimothyMakkison force-pushed the trivia_list_enumerator branch 3 times, most recently from f1f236e to da71f31 Compare October 13, 2025 11:31
@TimothyMakkison
TimothyMakkison force-pushed the trivia_list_enumerator branch 4 times, most recently from 83a2e47 to 286d295 Compare November 2, 2025 19:35
@TimothyMakkison
TimothyMakkison force-pushed the trivia_list_enumerator branch 3 times, most recently from be8c694 to ec65cc7 Compare November 14, 2025 22:58

@belav belav left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I'm not really sure how these ended up using Enumerable.Any as it is not something I prefer. I much prefer the extension methods especially if using them is more efficient!

@belav belav added this to the 1.3.0 milestone Dec 25, 2025
@belav
belav merged commit aa849db into belav:main Dec 25, 2025
7 checks passed
belav added a commit that referenced this pull request Dec 31, 2025
…#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>
belav added a commit that referenced this pull request Feb 20, 2026
…#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>
belav added a commit that referenced this pull request Mar 12, 2026
…#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>
belav added a commit that referenced this pull request Apr 4, 2026
…#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants