You are viewing a single comment's thread.

view the rest of the comments →

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).

0
0

[–] rwbj ago 

There's really no trade off in the garbage collector. You can deterministically execute it you so desire. All it does is ensure that you don't inadvertently leak memory to a point that it begins impacting your application or system's performance. If your application does not use significant memory - it will never run. If your application does use significant memory, and you'd like to free it - then you're also free to do that.

Branch misprediction on a bounds check means you just hit an exception, which is probably and should be fatal, in which case the misprediction cost is irrelevant.