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

perf: add Doc.Null check to Argument avoids Concat creation - #1706

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

belav merged 2 commits into
belav:mainfrom
TimothyMakkison:argument_null

Conversation

@TimothyMakkison

Copy link
Copy Markdown
Contributor

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

@TimothyMakkison
TimothyMakkison force-pushed the argument_null branch 2 times, most recently from ba5bc97 to fc263f1 Compare October 25, 2025 09:49

@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.

LGTM!

@belav
belav enabled auto-merge (squash) December 25, 2025 16:22
@belav
belav merged commit 5d45e5d into belav:main Dec 25, 2025
7 checks passed
@belav belav added this to the 1.3.0 milestone Dec 25, 2025
belav added a commit that referenced this pull request Dec 31, 2025
)

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>
belav added a commit that referenced this pull request Feb 20, 2026
)

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>
belav added a commit that referenced this pull request Mar 12, 2026
)

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>
belav added a commit that referenced this pull request Apr 4, 2026
)

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>
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