Hacker News new | ask | show | jobs
by soundarana 920 days ago
When you run a tight hot loop, GC has no impact.

Just like you wouldn't allocate smart pointers in a tight C++ loop.

You can do dumb slow things in both languages, and yes, C# programmers might be less informed about these topics, but it's not a language problem.

1 comments

This is not always true - for many GCs, threads need to suspend at least some of the time. If the compiler can't prove a small bound on the iterations of a loop, it needs to insert safe point instructions.

Also depending on the GC, read or write barriers may be required.

Lastly there are circumstances in generational moving GCs where there is extra overhead due to checking to and from space - for example if you attempt a compare-and-set on a reference type, you need extra code to check if your CAS failed due to comparing the from-space and to-space addresses of the same object.

I work primarily in garbage collected languages, and there are many benefits - safety, throughput, easy ABA avoidance in lock-free code - but using a GC carries tradeoffs.