#Optimization potential of using Object as a "Value" type

1 messages · Page 1 of 1 (latest)

rich spadeBOT
#

<@&987246399047479336> please have a look, thanks.

proven berry
#

while i do understand this is obviously bad design, would the more polymorphic approach open up more opportunity for the JVM to optimize its code?

#

its not obviously bad deign

#

its conditionally bad design

#

it is also important to note that "maintainability" isnt a factor here, im just asking about raw performance and optimization potential
The JIT can see through "method dispatch on a small set of classes" and "switching through type"

#

so i dont think there is any robust idea of perf difference

bleak swift
#

@quartz zenith I need to understand some concepts used here, You use the term type erased, that term is used normally with only generics, I'm guessing you mean that you want an umbrella class that just uses Object to represent the type of the value, which means that one class Value, with a field Object value, except you mean two classes using ValueObject and ValueInt, but if this is the case polymorphism is more performant, because the JVM can do more inlining to avoid dynamic dispatch during runtime as much as possible, that type dispatch must be handle by someone and instanceof can prevent further optimizations by the JVM

#

If that's the case then the behaviour wouold be conditional during runtime as well right?

#

That is you don't know whats coming in and then the behaviour would also be dynamic right?