$cast performance

In reply to Net:

There is no good reason to use $cast on anything other than class variables or enum encodings that require dynamic type checking. There might be a corner case for using $cast on other types when the variable’s types are parameterized and you want your code to work regardless of whether the types are assignment compatible or not. In that case the return value of $cast would be a constant. For assignment compatible types, 1’b1 gets returned and the assignment happens like a regular blocking assignment. For assignment incompatible types, 1’b0 gets returned and no assignment happens.

$cast never clones—it just copies the value in the source variable to the destination variable. In the case of a class object, it just copies the class handle.