top | item 38283836

(no title)

bhuber | 2 years ago

This is mostly true, but sometimes the cost of evaluating the condition itself is non-trivial. For example, if a and b are complex objects, even something as trivial as `if (a.equals(b)) ...` might take a relatively long time if the compiler/runtime can't prove a and b won't be modified between calls. In the worst case, a and b only differ in the last field checked by the equality method, and contain giant collections of some sort that must be iterated recursively to check equality.

discuss

order

wyager|2 years ago

"If the branch condition is not volatile, compilers will usually lift it"

Usually in any program with well-defined semantics (e.g. not using janky multithreaded mutability), this will be true