title: android kotlin - are Function References slow due to reflection?
body: <p><a href="https://kotlinlang.org/docs/reference/reflection.html" rel="nofollow noreferrer">Reflection</a> is suppose to be a bit time consuming on android. so i was wondering given a function reference like this:</p>
  <pre><code>fun isOdd(x: Int) = x % 2 != 0
  val numbers = listOf(1, 2, 3)
  println(numbers.filter(::isOdd))
  </code></pre>
  <p>is <strong>::isOdd</strong> call an unnecessary burden ?</p>
  <p>would it be more efficient to not use them ?</p>
  <p><em><strong>UPDATE</strong></em>:  doing some light metrics i did the following:</p>
  <pre><code>    class MainActivity : Activity() {
  
      val numbers = listOf(1, 2, 3)
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
  
          doRegular()
          doReflection()
      }
  
      fun isOdd(x: Int) = x % 2 != 0
  
      fun doRegular() {
          val start = System.currentTimeMillis()
          for (i in 0..999999) {
              numbers.filter { it % 2 != 0 }
          }
          Log.v(&quot;myTag&quot;, &quot;regular: +${System.currentTimeMillis() - start}&quot;)
      }
  
      fun doReflection() {
          val start = System.currentTimeMillis()
          for (i in 0..999999) {
              numbers.filter(::isOdd)
          }
          Log.v(&quot;myTag&quot;, &quot;reflection: ${System.currentTimeMillis() - start}&quot;)
      }
  }
  </code></pre>
  <p>and the print statement results are:</p>
  <pre><code>//*****this was the first attempt before compiler could optimise anything
          regular: +577     
          reflection: 318
    //*********
    
      regular: +376
      reflection: 327
      
      regular: +593
       reflection: 343
      
       regular: +417
       reflection: 251
       
       regular: +243
       reflection: 238
       
       regular: +241
       reflection: 238
       
       regular: +238
       reflection: 237
       
       regular: +235
       reflection: 247
       
       regular: +237
       reflection: 247
       
       regular: +230
       reflection: 268
  </code></pre>
  <p>What would you conclude given these results?</p>
  <p>update: some are asking why i think its using reflection. its based on this:</p>
  <p>This stackoverflow <a href="http://stackoverflow.com/a/52463397/835883">answer</a> seems to state its reflection:  and the title for the <a href="http://kotlinlang.org/docs/reference/reflection.html" rel="nofollow noreferrer">official doc</a> has reflection as the main heading:  hence my confusion.</p>