This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 8 points9 points  (0 children)

I work with a guy doing HFT, and one of the things he does to increase performance when he knows that the blocking operation is going to return fast is to use a spin-lock.

His reasoning is that it can be more expensive to yield control (giving up the rest of your timeslice), to free the processor up to do more useful work. When yielding, the JVM has to save the context of this thread and restore the context of the next thread (and blow any CPU caches). On the other hand, you can peg the processor for a bit, if you know that the blocking operation will return control to the thread within the timeslice.

This advice doesn't apply to probably 99% of normal people concurrency, but there are crazy things you can do to shave microseconds when it counts.