3 ms·
The key to garbage collection is… to go super far out of your way to avoid allocating memory. This is not ideal.
by forrestthewoods 4y ago
The key to garbage collection is… to go super far out of your way to avoid allocating memory. This is not ideal.
- girvo 4y agoI'm probably biased because I live in firmware development these days, but that's true even for non-garbage collected languages when it comes to making sure things are fast
- ekidd 4y agoSpeaking as someone who has spent time optimizing C++ and Rust, memory allocation in hot loops is often where performance goes to die. GC or not, if you want to fast, reducing allocation is one of the first things to benchmark. (One fast way to manage allocations is to use an arena allocator that allocates memory by incrementing a pointer, and frees memory all at once. This is pretty effective for simple, short-lived requests.)
- forrestthewoods 4y agoYes, minimize malloc in all cases. The difference is that GC languages are fundamentally designed around the concept that it’s cheap and easy to malloc/free. Avoiding allocations can be excruciatingly difficult. In C++ you also need to minimize allocations, but it’s radically easier to do in C++ than in C#.