Are `constructor`s automatically `inline`d?
# getting-started
b
Are `constructor`s automatically `inline`d?
v
benleggiero: why? I would thought the opposite, a constructor is never
inline
1
s
Inline doesn't mean "go faster", there's select cases where inlining pays off and usually the JVM can figure those out easily enough
b
I figured they're so simple that there's really no no benefit to pushing another stack frame unless it's a Cineplex constructor with a body
I'm thinking of things like this:
Copy code
class Foo(val bar: Bar) {
    constructor(baz: Baz): this(baz.toBar())
}

Foo(Baz())
What's the point of adding a new stack frame when we know
Foo(Baz())
is always always always going to be exactly the same as
Foo(Baz().toBar())
?
v
Stakframes? You are optimizing the wrong thing
b
What do you mean? Isn't the point of
inline
to pull the contents of a function out of its own stack frame and into the caller's
s
Yeah but it isn't always better. It can often be detrimental. This isn't native code where there are no runtime optimizations being performed
b
Sure, but I'd still think that `constructor`s, being possibly the simplest type of runnable code Kotlin defines, would be `inline`able