Skip to content
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

Combine all changes #1551

Closed
wants to merge 12 commits into from
Closed

Conversation

TimothyMakkison
Copy link
Contributor

@TimothyMakkison TimothyMakkison commented Mar 21, 2025

All my local/pending changes, I have a couple more ideas but this should give a general feel for the final performance

Method Mean Error StdDev Gen0 Gen1 Allocated
Default_CodeFormatter_Tests 64.72 ms 0.548 ms 0.512 ms 1666.6667 1000.0000 18.33 MB
Default_CodeFormatter_Complex 137.83 ms 2.730 ms 4.708 ms 3000.0000 1000.0000 30.78 MB

@Hona
Copy link

Hona commented Mar 23, 2025

This looks incredible @TimothyMakkison

Did you have a benchmark before and after any of your changes so we can estimate the total change?

@TimothyMakkison
Copy link
Contributor Author

TimothyMakkison commented Mar 23, 2025

This looks incredible @TimothyMakkison

Thanks 😄 optimisations are my favourite changes, very satisfying. OOC how did you find this PR?

Did you have a benchmark before and after any of your changes so we can estimate the total change?

See #1552 for benchmark performance before I made any changes. The before section of #1550 is the current performance.

Note that my changes only apply to the formatting logic, csharpier uses a caching system and only formats files that changed. This will be most beneficial when working on several medium to large files.

IIRC the bulk of the time running dotnet format . is mostly IO

Original #1552

Method Mean Error StdDev Median Gen0 Gen1 Gen2 Allocated
Default_CodeFormatter_Tests 233.3 ms 4.63 ms 8.23 ms 229.7 ms 11000.0000 4000.0000 1000.0000 101.41 MB
Default_CodeFormatter_Complex 433.7 ms 8.53 ms 7.56 ms 433.4 ms 20000.0000 5000.0000 1000.0000 182.44 MB

@Hona
Copy link

Hona commented Mar 24, 2025

I've been meaning to learn about performance and improving that in .NET. I was curious if you had any resources/courses that you'd recommend?

I have been 'watching' this repo on GitHub so I just see the list of PRs in my GH notifications, and I've been seeing all your awesome PRs in awe.

Thanks for that info and the old link - looks like pretty awesome speedups. I can't wait :)

@TimothyMakkison
Copy link
Contributor Author

TimothyMakkison commented Mar 24, 2025

I don't know what your day job is, but most day to day CRUD apps are bottlenecked by: IO, HTTP calls, bad mulithreading and database calls/SQL.

These optimisation are more applicable for libraries or high performance scenarios.

I'm not an expert but I'd recommend:

  • Being familiar with Span<T>/ReadOnlySpan<T>, it can be used instead of copying string or T[].
    • IMO ReadOnlySpan<T> can be semantically better than arrays.
  • Learning how to throw together a benchmark in BenchmarkDotNet
  • Be able to use a profiler
  • Looking at the internals of async, Linq, Func/closures.
    • It's pretty cool looking at how code is lowered and turned into IL code. Try using Sharplab or your IDEs built IL viewer
  • Reading Stephen Toub's performance improvements in .NET
    • These are great because they show real world examples of how to identify, profile and apply performance techniques such as stackalloc, ValueListBuilder etc
  • Andrew Locke has some good blog posts
  • CySharp have some great repos. Ive learned a lot from going through them. Neuecc is allergic to memory usage 😅
  • Nick Chapsas on youtube
  • The book Pro .NET Memory Management: For Better Code, Performance, and Scalability goes into a lot of depth on the CLR (I haven't read it, I've heard its pretty thorough)
    • IIRC they are pretty chill about piracy, so you can see if it's your cup of tea before buying a copy.
  • SIMD is cool but most problems don't have a direct use case for it😞

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.

None yet

2 participants