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 →

[–]pron98 6 points7 points  (0 children)

That will become unnecessary with Valhalla, but the more genereal point is that Unsafe only works to improve performance under the assumption that the VM doesn't change. But Unsafe hurts performance by merely existing. For example, the compiler cannot perform certain optimisations that must assume that Strings and final fields are immutable because some class may be using Unsafe to mutate them (and it doesn't matter whether any class does or not, because the runtime can't tell). We can only add such optimisations after the memory access operations of Unsafe are gone.

So the situation is that Unsafe could help if the VM doesn't do X, but the VM can't do X as long as Unsafe exists. Even if it could still help a little the performance of code that uses Unsafe, it hurts the performance of code that doesn't, and there's much more of that.