Skip to content

Conversation

@TimothyMakkison
Copy link
Contributor

@TimothyMakkison TimothyMakkison commented Oct 23, 2025

Check code for #if before running GetSymbolSets. Profiling pegs this method at around 5-7% of runtime.

A similar optimisation could be done for CSharpierIgnore comments, but the logic for this would probably be quite janky.

image

Benchmarks

Before

Method Mean Error StdDev Median Gen0 Gen1 Allocated
Default_CodeFormatter_Tests 132.2 ms 3.14 ms 8.82 ms 128.5 ms 3000.0000 1000.0000 34.57 MB
Default_CodeFormatter_Complex 263.6 ms 5.13 ms 7.02 ms 262.6 ms 5000.0000 2000.0000 53 MB

After

Method Mean Error StdDev Median Gen0 Gen1 Allocated
Default_CodeFormatter_Tests 120.8 ms 4.24 ms 12.02 ms 115.6 ms 2000.0000 1000.0000 31.22 MB
Default_CodeFormatter_Complex 245.5 ms 4.91 ms 7.35 ms 243.7 ms 5000.0000 2000.0000 51.73 MB

@TimothyMakkison
Copy link
Contributor Author

TimothyMakkison commented Oct 26, 2025

Added check for // csharpier-ignore using SearchValue.

  • Not sure about the namings
    • CodeInformation vs CodeFacts, PrinterContextInformation
    • Information vs Facts, MetaData
  • The logic to skip calls to HasLeadingCommentMatching could be changed, right now I use if statements before the call, I did consider changing HasLeadingCommentMatching and CSharpierIgnore.HasIgnoreComment to take a context and then check for it there. I don't know which is more idiomatic

This PR should be re-evaluated after #1703 is merged.
Better than #1718

Benchmarks

Preprocessor Check

Method Mean Error StdDev Median Gen0 Gen1 Allocated
Default_CodeFormatter_Tests 110.6 ms 2.71 ms 7.41 ms 107.7 ms 2000.0000 1000.0000 31.22 MB
Default_CodeFormatter_Complex 236.4 ms 4.70 ms 7.03 ms 236.5 ms 5000.0000 2000.0000 51.66 MB
Method Mean Error StdDev Median Gen0 Gen1 Allocated
Default_CodeFormatter_Tests 110.6 ms 2.10 ms 5.81 ms 108.8 ms 2000.0000 1000.0000 31.22 MB
Default_CodeFormatter_Complex 239.8 ms 4.47 ms 6.27 ms 238.4 ms 5000.0000 2000.0000 51.67 MB
Method Mean Error StdDev Gen0 Gen1 Allocated
Default_CodeFormatter_Tests 109.5 ms 2.04 ms 3.52 ms 2000.0000 1000.0000 31.22 MB
Default_CodeFormatter_Complex 236.7 ms 4.69 ms 5.40 ms 5000.0000 2000.0000 51.68 MB

Preprocessor + Ignore Check

Method Mean Error StdDev Median Gen0 Gen1 Allocated
Default_CodeFormatter_Tests 107.7 ms 2.14 ms 5.81 ms 106.0 ms 2000.0000 1000.0000 31.16 MB
Default_CodeFormatter_Complex 232.5 ms 4.38 ms 7.31 ms 229.9 ms 5000.0000 2000.0000 51.64 MB
Method Mean Error StdDev Gen0 Gen1 Allocated
Default_CodeFormatter_Tests 107.8 ms 2.15 ms 5.36 ms 2000.0000 1000.0000 31.16 MB
Default_CodeFormatter_Complex 232.9 ms 4.54 ms 7.20 ms 5000.0000 2000.0000 51.69 MB
Method Mean Error StdDev Median Gen0 Gen1 Allocated
Default_CodeFormatter_Tests 111.2 ms 3.32 ms 8.98 ms 108.6 ms 2000.0000 1000.0000 31.16 MB
Default_CodeFormatter_Complex 227.2 ms 4.35 ms 7.26 ms 225.9 ms 5000.0000 2000.0000 51.64 MB
Method Mean Error StdDev Gen0 Gen1 Allocated
Default_CodeFormatter_Tests 106.9 ms 2.71 ms 7.22 ms 2000.0000 1000.0000 31.16 MB
Default_CodeFormatter_Complex 230.6 ms 4.61 ms 6.46 ms 5000.0000 2000.0000 51.59 MB

@TimothyMakkison TimothyMakkison force-pushed the contains_prepro branch 2 times, most recently from 29b1e39 to fb10733 Compare October 26, 2025 21:00
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.

1 participant