-1

I was recently learning about Kotlin inline functions. I thought the below function, twipsToPixels, seemed like a good use-case for that, but IntelliJ gives me a warning saying there's an "expected performance impact". I would've thought the opposite would be true here? This makes me think I'm missing something deeper. Does anyone have any thoughts?

private inline fun twipsToPixels(value: Int) = (value * SCREEN_RESOLUTION / TWIPS_CONVERSION).roundToInt()

private fun screenBoxInPixels(screenBox: ScreenBox): ScreenBox {
  val left = twipsToPixels(screenBox.position.left)
  val top = twipsToPixels(screenBox.position.top)
  val width = twipsToPixels(screenBox.size.width)
  val height = twipsToPixels(screenBox.size.height)
  return ScreenBox(Position(left, top), Size(width, height))
}
Thomas
  • 29
  • 2
  • Mainly `reified` parameters are the reason for inlining. A good JVM will inline methods anyway if that's efficient. – al3c Mar 06 '20 at 15:24
  • 1
    https://stackoverflow.com/questions/44471284/when-to-use-an-inline-function-in-kotlin – Saeed Entezari Mar 06 '20 at 15:25
  • Does this answer your question? [when to use an inline function in Kotlin?](https://stackoverflow.com/questions/44471284/when-to-use-an-inline-function-in-kotlin) – matt freake Mar 06 '20 at 17:25

1 Answers1

1

but IntelliJ gives me a warning saying there's an "expected performance impact"

You misread it; it says this impact is insignificant, that is, probably too small to bother. The second part of the message is

Inlining works best for functions with parameters of functional types

mainly because it allows avoiding creating function objects for these parameters in the first place.

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487