controlflow / resharper-heapview

ReSharper Heap Allocations Viewer plugin
MIT License
303 stars 28 forks source link

How do we find out what the warnings mean? #92

Closed MrYossu closed 1 year ago

MrYossu commented 2 years ago

Sorry if this is a dumb question, but I just installed the plugin, and it's highlighted all sorts of things in my code.

Whilst some of the tooltips explain the issue, a lot of them aren't clear enough (for me at least). Is there any way of finding out more details?

For example, I have some code that uses the LanguageExt package, and on the following line (end of a series of calls to Bind)...

.Match(_ => Task.Run(TidyUpAfterDocumentCreation), async ex => await EmailException(ex));

...I get a few warnings, all underlined in orange...

There are plenty more, but the warnings are too terse for my level of knowledge. I'd like to know what it's warning me about, so I can fix them and (hopefully) write better code.

Thanks

matkoch commented 2 years ago

Hi @MrYossu

the highlightings are not actually meant as "warnings" but rather to give you a view of where allocations happen. In many cases, allocations are just unavoidable. If we're talking about "fixing" something, then this should be based on upfront performance measurements. So – you have a definite reason to investigate and restructure your code.

With some libraries, you might end up with highlightings all over the place although it's just used as intended. For these situations, I'd recommend either disabling the specific highlighting (via options dialog) or all HeapView highlightings via comments (available through Alt-Enter menu).

MrYossu commented 2 years ago

@matkoch Thanks for the reply.

I understand about not falling into the trap of premature optimisation, but given that it shows me these warnings, it would be nice to know what they mean, as in some cases, I may be able to make a small change that reduces the allocations. Also, if I see performance issues, I would want to understand what is being allocated and how, so I can address the issues.

So I do need to know what the plug-in is telling me, otherwise it's just adding noise to my code.

Thanks again.

matkoch commented 2 years ago

Theoretically, we could show a "Why is ReSharper/Rider suggesting this?" item per inspection. However, at the moment I'm afraid this is not planned to be added to the plugin. @controlflow as the author may correct me.

Unfortunately, the best thing I can suggest is googling and reading articles and blog posts. Some of these are very detailed and require good knowledge about the compiler. Others may even not be "fixable", for instance when you need an array of reasonable size, you will have to allocate it. Again, these are not warnings but just meant to provide a view into allocations.

MrYossu commented 2 years ago

@matkoch OK, thanks