Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/controlflow/resharper-heapview
ReSharper Heap Allocations Viewer plugin
https://github.com/controlflow/resharper-heapview
Last synced: 7 days ago
JSON representation
ReSharper Heap Allocations Viewer plugin
- Host: GitHub
- URL: https://github.com/controlflow/resharper-heapview
- Owner: controlflow
- License: mit
- Created: 2014-04-30T13:46:10.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-04-16T10:05:55.000Z (7 months ago)
- Last Synced: 2024-05-02T04:31:07.349Z (7 months ago)
- Language: C#
- Size: 8.57 MB
- Stars: 299
- Watchers: 18
- Forks: 28
- Open Issues: 10
-
Metadata Files:
- Readme: Readme.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
HeapAllocationViewer for Rider and ReSharper
--------------------------------------------[![Rider](https://img.shields.io/jetbrains/plugin/v/9223-heap-allocations-viewer.svg?label=rider&colorB=0A7BBB&style=for-the-badge&logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAADAAAAAsCAYAAAAjFjtnAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuMjHxIGmVAAAEEklEQVRoQ%2B2ZS0hUURjHLSoKominVIta1aLaFYhBES1t1bLFRCAREbQKaiHpqgeEpjDjRhIFHWwzIyo6oWXqwmfkW0evr9TxNT7GcZxX%2FzPzzZk53jsyc%2B91I%2FcHB4a5%2F%2B%2B79z%2Fn3O98RzOOBKFQ6BeGlOrw%2B%2F2S0%2Bn83dXV9a6srOwSpUlKfX19yvnn5%2BelwcFBW09Pz8uamporlOJgEOgMq2R7ezuAm33Cx%2BOUTgYMqMq%2Ft7cX7O3t7QbXKJUyWgzEWFhYaMONTlJKAbUGYvh8vjBymy0Wi2J%2BXQwwxsbGvlFKAa0G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S%2BsNH6UCjBfZ3HJgwDKQMDLzGKNRrwECh2%2B0WjpUGimRk%2FAdgThdOY4UJ9QAAAABJRU5ErkJggg%3D%3D)](https://plugins.jetbrains.com/plugin/9223-heap-allocations-viewer)
[![ReSharper](https://img.shields.io/jetbrains/plugin/v/12390-heap-allocations-viewer.svg?label=resharper&colorB=0A7BBB&style=for-the-badge&logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAADIAAAAxCAYAAACYq%2FofAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuMjHxIGmVAAAE%2BElEQVRoQ%2B2Ya0hkZRzG3d1oWehLLQS2QRC1tEWflhLqU0QgsbAb6ZesiL5KXxKE3GBa86uE0IdWiTJq8BLGMiqapnjDYfAy3jCv6XgfZC7explxnJ73zDPvnOM7M%2BtlslrOD%2F7InOc5%2F%2Ff8z3mvZplkgJKSkuzS0tIb8bBYLC9RMoDr1%2FW%2B4uLiG5RUDg8PFxCek4Tf7%2Fe4XK7W0dHRosbGxieZ6tg4nU7%2F3t5eNB67u7tBSpK8vLwr29vbXr1veno6Ci7QYgSCT6inJRQK7UxNTd3F23ucKR%2FGBbyMAG%2FXWFpaClCT2Gy2F4PBIB0x0FYbZRXoZyokzszMTFdtbe0Vpk1JTU3NawcHB7wrBn7XU5a0tLS8Q1kyNDRko6wCPSOFCCYnJ2uYNiXLy8tv0y4ZHx%2F%2FnrIEL6aIsmRlZeUzyirQM1YI3mxodXX1OaZOCvr517RLPB7PR5QlGH9WyhIM%2BDzKKtCVQtCHf8Cfi0ejsLDwGfTdj2dnZ23hcPgQ1xRQSAVTayDXbYQ1Hmtra7u0SlDc4djYWEQfW1tbVBNMTExoWldX1wzTJ4CetBDKKbHb7Rb4eEeCjY2NOVo04PmCUsbAyzC0oYHrpyokNzf3Mvp7mLdIcO%2F%2Fqx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6HgYEB5YSYKdjE%2BfDIFOJ0Ol1sN%2BOwifMB7T2Bc%2FrT%2F0SwCZOHk5X1N%2Fu%2FydjP06PFAAAAAElFTkSuQmCC)](https://plugins.jetbrains.com/plugin/12390-heap-allocations-viewer)This plugin statically analyzes C# code to find all local object allocations happening.
It can be used to reduce number of heap allocations in hot paths of your C# program.
![Example](https://raw.githubusercontent.com/controlflow/resharper-heapview/master/Content/Example.png)
#### Features
* It can detect and visualize [all boxing cases](http://stackoverflow.com/questions/7995606/boxing-occurrence-in-c-sharp), including:
```c#
struct Boxing {
void M(string a) {
object obj = 42; // implicit conversion Int32 ~> Object
string path = a + '/' + obj; // implicit conversion Char ~> Object
int code = this.GetHashCode(); // non-overriden virtual method call on struct
string caseA = E.A.ToString(); // the same, virtual call
IComparable comparable = E.A; // valuetype conversion to interface type
Action action = this.M; // delegate from value type method
Type type = this.GetType(); // GetType() call is always virtual
}enum E { A, B, C }
}
```
* It can visualize some hidden allocations happening in C#, including:
```c#
class HeapAllocations {
List _xs = new List(); // explicit object creation expressions
int[] _ys = {1, 2, 3}; // allocation via array initializer syntaxvoid M(params string[] args) {
string c = args[0] + "/"; // string concatenation
M("abc", "def"); // parameters array allocation
M(); // the same, hidden 'new string[0]'
var xs = Enumerable.Range(0,1); // iterator method call
var ys = from x in xs
let y = x + 1 // anonymous type creation for 'let'
select x + y;
}void N(List xs) {
foreach (var s in xs) F(s); // no allocations, value type enumeratorIEnumerable ys = xs;
foreach (var s in ys) F(s); // IEnumerator allocation in foreach
}
}
```
* It can detect delegate instances allocation, ignoring cached delegates:
```c#
class Delegates {
static void M(string s) {
Action method = M; // non-cached delegate from method group
Action lambda = () => M("a"); // cached delegate from static lambda
Action closure = () => M(s); // non-cached lambda with closure 's'
}void M() {
Action generic = () => { }; // non-cached, lambda in generic method
Action closure = () => M(); // non-cached, captures 'this' to closure
}
}
```
* It can detect closure ("display classes") creation points:
```c#
class Closures {
IEnumerable StupidExample(string str) {
// <= hidden closure class allocation happens here
if (str == null)
return Enumerable.Empty();if (str.Length == 0) {
return Enumerable.Empty();
} else {
// <= second hidden closure allocation (nested closure)
int value = str.Count(x => x == '_');return Enumerable
.Range(0, str.Length)
.Select(count => // delegate instance allocation
str.Substring(Math.Max(value, count)));
}
}
}
```#### Notes
* Please, avoid premature optimizations. Use this tool with care, only when it matters to reduce allocations count;
* You can change default colors of highlightings in Visual Studio settings: go *Tools* - *Settings* - *Fonts and colors*
and check colors for items *"ReSharper HeapView Boxing"* and *"ReSharper HeapView Allocation"*;
* You can change highlighting severity or search for all issues in project/solution as usual - via Alt+Enter menu over highlighting;
* This plugin highly relies on Microsoft's implementation of C# compiler shipping with VS,
it may produce false positives for other C# implementations like Mono C# compiler;
* Plugin's [changelog is here](CHANGELOG.md).