Skip to content

Conversation

@TimothyMakkison
Copy link
Contributor

@TimothyMakkison TimothyMakkison commented Oct 21, 2025

Replace boxing, Linq and ToImmutableHashSet call with a manual ValueListBuilder version.

  • Added a basic contains method because I can't get the built in Span.Contains to work generically with enums 🤷
    • Note that the hashset rarely goes above 4 items in my tests, so we won't be missing out on any vectorisation

Thought I'd already pushed this, I'll go through my backlog and see what else I've missed

Benchmark (timing is inaccurate)

Before

Method Mean Error StdDev Median Gen0 Gen1 Allocated
Default_CodeFormatter_Tests 130.5 ms 2.59 ms 6.11 ms 128.2 ms 3000.0000 1000.0000 34.58 MB
Default_CodeFormatter_Complex 261.4 ms 5.16 ms 7.87 ms 260.0 ms 5000.0000 2000.0000 53.04 MB

After

Method Mean Error StdDev Median Gen0 Gen1 Allocated
Default_CodeFormatter_Tests 140.1 ms 4.20 ms 12.00 ms 136.2 ms 3000.0000 1000.0000 34.55 MB
Default_CodeFormatter_Complex 265.4 ms 5.20 ms 6.95 ms 265.9 ms 5000.0000 2000.0000 51.99 MB

@TimothyMakkison
Copy link
Contributor Author

TimothyMakkison commented Oct 29, 2025

Turns out it was boxing SyntaxKind to do the comparison, fixed the issue and re-ran the benchmarks. Contains doesn't need to be generic, so I made Contains(SyntaxKind)

Method Mean Error StdDev Median Gen0 Gen1 Allocated
Default_CodeFormatter_Tests 212.6 ms 9.17 ms 26.30 ms 205.3 ms 3000.0000 1000.0000 34.47 MB
Default_CodeFormatter_Complex 321.9 ms 25.77 ms 75.97 ms 287.8 ms 5000.0000 2000.0000 51.58 MB

Timing is inaccurate, this was done in bed 😅

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