title: Why LiveData is slow
body: <p>In my application, I load data from the local database and it's very slow. I tried to find what is slow and I found that this occurs because of LiveData.</p>
  <p>I created a sample application to test LiveData speed here you are my test code:
  FirstFragment:</p>
  <pre><code>class FirstFragment : Fragment(), FirstFragmentCallback {
  private val TAG = FirstFragment::class.java.simpleName
  
  private var mViewModel: FirstFragmentViewModel? = null
  
  
  override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      mViewModel = ActivityUtils.obtainViewModel(requireActivity(), FirstFragmentViewModel::class.java)
      (mViewModel as FirstFragmentViewModel).callback = this
  }
  
  override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
      val v = inflater.inflate(R.layout.first_fragment, container, false)
      Log.d(TAG, &quot;onCreateView called&quot;)
  
      registerObservables()
      mViewModel?.loadData()
      return v
  }
  
  override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
      super.onViewCreated(view, savedInstanceState)
      val secondFragmentButton = view.findViewById&lt;Button&gt;(R.id.second)
      secondFragmentButton.setOnClickListener {
          ActivityUtils.replaceFragmentInActivity(requireFragmentManager(), SecondFragment(), R.id.container, false)
      }
  }
  
  private fun registerObservables(){
      mViewModel?.dataLoadedEvent?.observe(this, Observer {
          Log.d(TAG, &quot;dataLoaded event&quot;)
      })
      mViewModel?.dataLoaded2Event?.observe(this, Observer {
          Log.d(TAG, &quot;dataLoaded2 event&quot;)
      })
  }
  
  override fun dataLoaded() {
      Log.d(TAG, &quot;dataLoaded callback&quot;)
  }
  }
  </code></pre>
  <p>FirstFragmentViewModel:</p>
  <pre><code>class FirstFragmentViewModel(val mAppliction: Application): AndroidViewModel(mAppliction) {
  
  val dataLoadedEvent: SingleLiveEvent&lt;Void&gt; = SingleLiveEvent()
  
  val dataLoaded2Event: MutableLiveData&lt;Void&gt; = MutableLiveData()
  
  var callback: FirstFragmentCallback? = null
  
  fun loadData(){
      dataLoadedEvent.postValue(null)
      dataLoaded2Event.postValue(null)
      callback?.dataLoaded()
  }
  }
  </code></pre>
  <p>If I run this fragment I got these in the LogCat:</p>
  <blockquote>
  <p>2019-05-15 13:23:07.405 8632-8632/livedatatest D/FirstFragment: onCreateView called</p>
  <p>2019-05-15 13:23:07.406 8632-8632/livedatatest D/FirstFragment: dataLoaded callback</p>
  <p>2019-05-15 13:23:07.438 8632-8632/livedatatest D/FirstFragment: dataLoaded event</p>
  <p>2019-05-15 13:23:07.439 8632-8632/livedatatest D/FirstFragment: dataLoaded2 event</p>
  </blockquote>
  <p>You can see that <code>dataLoadedEvent.postValue(null)</code> take at least 30ms, but the simple callback is called immediately.</p>
  <p>Is there any solution to speed up LiveData events?</p>