very true words!
I have not known this is because of wait(), but [...] it really does matter!
This isn't really surprising. JCL was so kind to share some more insight about wait a few months ago:
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=410383#Post410383They way wait() works is inherently counter productive for any modern processor, aside from the fact that it might have to copy a non trivial amount of data. The real pain is the jumping around, while in theory it's not that bad to use a jump (or function call), it is bad if the CPU can't predict it. CPUs like to use otherwise unused time trying to predict the future, which is a little bit of black magic vodoo, a lot of caching, and juggling with heuristics. I have briefly mentioned this in my last
blogpost, and there is a famous
StackOverflow question about this very thing.
The problem is, executing your actual function might not even take long, in fact, it's probably incredibly fast. A vec_dist() here, some more math there, peanuts for a modern CPU. But the real killer is the jump that has to be done in and out of your function, the CPU is unable to predict the target and thus when the jump occurs, it has to empty more or less the complete cache. Cache misses are incredibly expensive, and working with a cold cache for most of the time is a horrible performance killer.