0
0

[–] enneract ago 

How can a managed language possibly be as fast as native code? All the run-time checks and especially garbage collection aren't free.

0
1

[–] rwbj 0 points 1 point (+1|-0) ago 

The garbage collector is pretty smart. It's not just going to randomly start arbitrarily running. It waits until it absolutely has to. It's also now nonblocking/asynchronous which makes it extremely low cost in most practical scenarios. The same is true of the run-time stuff. For instance in most practical scenarios where you're iterating on a non-mutated value, the bounds checks will be able to be completely optimized away. And even when it isn't able to be optimized away most modern architectures are going to be doing predictive execution (and other little tricks) that makes the check practically free.

0
0

[–] enneract ago  (edited ago)

It waits until it absolutely has to.

So the trade-off here is increased memory usage. On the other hand, there is no garbage collector in C++, so programs written in it can both be fast and not waste memory.

most modern architectures are going to be doing predictive execution (and other little tricks)

Branch predictors aren't perfect though, and mispredictions can be very costly. If you want speed, you want as few branches as possible (so as few run-time checks as possible).