Skip to content

perf: add PooledHashSet and PooledStringBuilder #1550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

TimothyMakkison
Copy link
Contributor

@TimothyMakkison TimothyMakkison commented Mar 21, 2025

Use PooledHashSet and PooledStringBuilder, I'm only using it for DocPrinter.Output and PropagateBreaks.alreadyVisitedSet as they get to upwards of 50,000 items. I don't reuse very large objects to prevent cases where a massive file creates some large objects and they are never garbage collected, eating up space.

I'll look into benchmarking this change with a real world large repo.

Are there any instances where csharpier is kept running for a long time? This change is beneficial for projects with lots of medium sized files but passively uses more memory. I'm a bit worried this will eat up 64 MB when using csharpier as an extension.

I can mitigate this with a cleanup function if needed.

Related

Benchmarks

Before

Method Mean Error StdDev Median Gen0 Gen1 Allocated
Default_CodeFormatter_Tests 103.5 ms 2.05 ms 3.70 ms 101.9 ms 2000.0000 1000.0000 31.07 MB
Default_CodeFormatter_Complex 190.2 ms 3.41 ms 6.31 ms 188.3 ms 5000.0000 2000.0000 54.57 MB

After

Method Mean Error StdDev Gen0 Gen1 Gen2 Allocated
Default_CodeFormatter_Tests 92.99 ms 1.651 ms 1.544 ms 3000.0000 1666.6667 333.3333 27.01 MB
Default_CodeFormatter_Complex 173.29 ms 2.924 ms 5.420 ms 5000.0000 2000.0000 - 49.65 MB

@TimothyMakkison TimothyMakkison marked this pull request as draft March 21, 2025 19:21
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