[JIT] Questions & suggestions regarding escape analysis and heap allocation analyzers #131687
Replies: 6 comments 3 replies
|
Tagging subscribers to this area: @dotnet/area-meta |
|
I'm a bot. Here is a possible related and/or duplicate issue (I may be wrong): |
|
I read through #70387, but I think my idea is a bit different. That issue proposed adding new attributes like Since I'm still a student learning how .NET works under the hood, I wanted to ask:
I'd love to hear what the team thinks. Thanks! |
|
Talking more about GC pausing, it can't be eliminated if any heap allocation is happening. It can only be reduced. Aside from reducing GC pressue, it's also important to optimize GC itself (#115627). |
|
@huoyaoyuan and @MichalPetryka Thank you both, this really helped me understand it better! I didn't know the JIT already had more information available than a separate tool could have before compiling. That explains a lot. I looked into issue #104936 and saw there's already active work on stack-allocating closures and other cases really cool to see this moving forward. Thanks for taking the time to explain this to me I really appreciate it! |
|
Good question. Look into GC.TryStartNoGCRegion() and GC.EndNoGCRegion() |
Uh oh!
There was an error while loading. Please reload this page.
Hi everyone,
I'm a CS student, not a professional developer, so I don't know all the deep technical details of how the compiler works. C# is my favorite language — I find it much easier to read and write than C++ or Rust, which honestly give me a headache.
But I know C# has one disadvantage in performance-critical fields (robotics, real-time systems, high-frequency trading): the Garbage Collector can cause small pauses that C++ doesn't have.
I found out there used to be tools for this:
RoslynClrHeapAllocationAnalyzer: a Microsoft tool that warned about heap allocations (archived in 2022).
HotPathAllocationAnalyzer: a community project that picked up the idea and added an attribute to mark a method as "no allocations allowed here."
My question/idea: would it make sense for Microsoft to officially bring back and maintain a tool like this? Not a change to the language itself — just a build-time analyzer that tells you "hey, this line will allocate memory, are you sure?" for people writing performance-critical C#.
I know C# probably won't fully replace C++ or Rust in every case, but I think small steps like this could help close the gap in scenarios where it matters. Sorry if this has already been discussed somewhere — I'm still learning and happy to be pointed to existing conversations!
All reactions