title: Flutters resource load faster than native Android
body: <p>I'm trying to convert image taken from resources to ByteArray which 
  will later be send through Socket. I've been measuring time of each of this conversion.</p>
  
  <p>I've done it on both Flutter and native Android (Kotlin). All of the test were done on the same image which was about 1-2MB. </p>
  
  <p>Flutter code :</p>
  
  <pre><code> sendMessage() async {
      if (socket != null) {
        Stopwatch start = Stopwatch()..start();
        final imageBytes = await rootBundle.load('assets/images/stars.jpg');
        final image = base64Encode(imageBytes.buffer.asUint8List(imageBytes.offsetInBytes, imageBytes.lengthInBytes));
        print('Converting took ${start.elapsedMilliseconds}');
        socket.emit("message", [image]);
      }
    }
  </code></pre>
  
  <p>Kotlin code:</p>
  
  <pre><code> private fun sendMessage() {
          var message = ""
          val thread = Thread(Runnable {
              val start = SystemClock.elapsedRealtime()
              val bitmap = BitmapFactory.decodeResource(resources, R.drawable.stars)
              message = Base64.encodeToString(getBytesFromBitmap(bitmap), Base64.DEFAULT)
              Log.d("Tag", "Converting time was : ${SystemClock.elapsedRealtime() - start}")
          })
          thread.start()
          thread.join()
          socket.emit("message", message)
      }
  
    private fun getBytesFromBitmap(bitmap: Bitmap): ByteArray? {
          val stream = ByteArrayOutputStream()
          bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream)
          return stream.toByteArray()
    }
  
  </code></pre>
  
  <p>I've been actually expecting native code to be much much faster than Flutter's but thats not the case.. Conversion for Flutter takes about 50ms and its around 2000-3000ms for native. 
  I thought that Threading may be the case, so I've tried to run this conversion on background thread for native code but it didn't help. 
  Can you please tell me why is there such a different in time, and how I can implement it better in native code? Is there a way to omit casting to Bitmap etc.? Maybe this makes it so long.</p>
  
  <p>EDIT. Added getBytesFromBitmap function</p>