Hacker News new | ask | show | jobs
by thomaslee 3079 days ago
> The answer would be no in general, I think, since it is unsafe. > ... > for example, the statement may include an rpc, and we don't want to make that rpc under the lock

I do agree that it's not a "safe" optimization in the extreme general case (so don't go rewriting your code assuming it's equivalent!), but in the case where the loop is a candidate for unrolling it works just fine. Imagine you had a more CPU- or memory-bound workload, and these benchmarks are a whole lot more interesting.

Put another way: if there's an RPC call in the for loop, the time spent in the RPC will dwarf the work involved in executing loop itself so ... odds are good it's not going to be a candidate for unrolling anyways. :)