Skip to content

Conversation

@TimothyMakkison
Copy link
Contributor

@TimothyMakkison TimothyMakkison commented Oct 20, 2025

  • Use Func<IReadOnlyList<SyntaxToken>, PrintingContext, Doc> to prevent closure formation.
  • Replace Array.IndexOf with a switch expression
  • Pass Comparison<SyntaxToken> to Array,Sort to prevent delegate creation each time.

I did experiment with a Doc.Join overload that takes a collection, a Func<TElement, PrintingContext, Doc> and PrintingContext, it did save 1.2MB but it is ugly as sin and awkward to use.

Benchmark (Timing is inaccurate)

Before

Method Mean Error StdDev Gen0 Gen1 Allocated
Default_CodeFormatter_Tests 222.8 ms 17.65 ms 51.50 ms 3000.0000 1000.0000 34.58 MB
Default_CodeFormatter_Complex 360.0 ms 11.02 ms 31.79 ms 5000.0000 2000.0000 53 MB

After

Method Mean Error StdDev Median Gen0 Gen1 Allocated
Default_CodeFormatter_Tests 137.5 ms 4.25 ms 12.00 ms 133.6 ms 3000.0000 1000.0000 34.54 MB
Default_CodeFormatter_Complex 268.2 ms 5.26 ms 13.57 ms 263.0 ms 5000.0000 2000.0000 52.6 MB

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