Is there any overhead at all in using case classes in Scala versus regular classes? Does it use any extra memory, do more in construction, or do more in field access? Or is it literally just free equals/hashcode/tostring/apply/unapply/etc for classes at the bottom of the type hierarchy?
My use case is a class that deserves to be a case class (immutable and equal if all fields are equal), but I’m in a domain where performance is critical.
(Please don’t answer along the lines of “stop worrying about premature optimization”.)
Case classes always keep all their parameters as fields. Other classes do only if their parameters are referenced by some method. That’s the only performance difference I can think of, except for larger code size due to the extra methods.