title: How to make Room DB insertion faster?
body: <p>I am inserting only 1000 object into Room Database using Rx-Android but it is taking at-least 7 minutes. How can I make it faster? </p>
  
  <p>I am using retrofit to fetch data from server with paging and using zip operator of RxJava to fetch them in parallel. I am getting all the data within 24 seconds but while I am inserting them into Room DB, it is taking atleast 7 minutes to insert them and sometimes taking more than 10 minutes.
  I have tried to insert all 1000 objects together, by 100 and also one by one but getting the same result each time. I have read some article regarding insertion delay and found it takes upto 64 sec for 1000 object.</p>
  
  <p>GroupA entity</p>
  
  <pre><code>@Entity(tableName = "group_a")
  public class GroupA {
  
      @Expose
      @PrimaryKey
      @NonNull
      private String _id;
      @Expose
      @TypeConverters(AbracketseConverter.class)
      private List&lt;Abracketse&gt; abracketses;
      @Expose
      private String createdate;
      @Expose
      private String group;
      @Expose
      private String headercolumna;
      @Expose
      private String headercolumnb;
      @Expose
      @TypeConverters(StringConverter.class)
      private List&lt;String&gt; morelist;
      @Expose
      private Long sequence;
      @Expose
      private String subheader;
      @Expose
      private String updatedate;
  }
  </code></pre>
  
  <p>Abracketse</p>
  
  <pre><code>public class Abracketse {
  
      @Expose
      private String columna;
      @Expose
      private String columnb;
      @Expose
      private String columnc;
      @Expose
      private String columnd;
      @Expose
      private String columne;
      @Expose
      private String columnf;
      @Expose
      private String columng;
  }
  </code></pre>
  
  <p>Room database</p>
  
  <pre><code>@Database(entities = {
          RecentSearchModel.class,
          Calculator.class,
          GroupA.class,
          GroupB.class
  }, version = 2, exportSchema = false)
  public abstract class MyRoomDatabase extends RoomDatabase {
  
      public abstract SearchDAO searchDAO();
      public abstract CalculatorDAO calculatorDAO();
      public abstract GroupADAO groupADAO();
      public abstract GroupBDAO groupBDAO();
  
  }
  </code></pre>
  
  <p>GroupA DAO</p>
  
  <pre><code>@Dao
  public interface GroupADAO {
  
      @Insert(onConflict = OnConflictStrategy.REPLACE)
      Completable insertAllGroupA(List&lt;GroupA&gt; groupAList);
  
      @Insert(onConflict = OnConflictStrategy.REPLACE)
      void insertGroupA(GroupA groupA);
  
      @Query("SELECT * FROM group_a")
      Single&lt;List&lt;GroupA&gt;&gt; getAllGroupA();
  
  }
  </code></pre>
  
  <p>Room instance from Application class</p>
  
  <pre><code>public static MyRoomDatabase getDatabase() {
          if (DB_INSTANCE == null) {
              synchronized (MyRoomDatabase.class) {
                  if (DB_INSTANCE == null) {
                      DB_INSTANCE = Room.databaseBuilder(context,
                              MyRoomDatabase.class, "my_database")
                              .fallbackToDestructiveMigration()
                              .build();
                  }
              }
          }
          return DB_INSTANCE;
      }
  </code></pre>
  
  <p>Fetching data from server and merging them</p>
  
  <pre><code> APIs apIs = RetroCliet.getClient();
          List&lt;Observable&lt;List&lt;GroupA&gt;&gt;&gt; observableRequestList = new ArrayList&lt;&gt;();
          for (int i = 0; i &lt; 11; i++) {
              observableRequestList.add(apIs.getGroupAMedicineList(new MedDataFetchBody(i)).subscribeOn(Schedulers.io()));
          }
          List&lt;GroupA&gt; result1 = new ArrayList&lt;&gt;();
          Observable&lt;List&lt;GroupA&gt;&gt; result = Observable.zip(observableRequestList, objects -&gt; {
              for (Object object : objects) {
                  for (Object childObject : (List&lt;GroupA&gt;) object) {
                      result1.add((GroupA) childObject);
  
                  }
              }
              return result1;
          });
  
          result.observeOn(AndroidSchedulers.mainThread())
                  .subscribeWith(new Observer&lt;List&lt;GroupA&gt;&gt;() {
                      @Override
                      public void onSubscribe(Disposable d) {
                          disposable.add(d);
                      }
                      @Override
                      public void onNext(List&lt;GroupA&gt; groupAS) {
  
                      }
                      @Override
                      public void onError(Throwable e) {
                          CustomDialog.dismissDialog();
                          reTryDialouge();
                      }
                      @Override
                      public void onComplete() {
                          insertToDB(result1);
                      }
                  });
  </code></pre>
  
  <p>Inserting data to Room</p>
  
  <pre><code> Completable.fromAction(() -&gt; MyApplication.getDatabase().groupADAO().insertAllGroupA(groupAS)
                  .subscribeOn(Schedulers.io())
                  .observeOn(AndroidSchedulers.mainThread())
                  .subscribe(new CompletableObserver() {
                      @Override
                      public void onSubscribe(Disposable d) {
                          disposable.add(d);
                      }
                      @Override
                      public void onComplete() {
  
                      }
                      @Override
                      public void onError(Throwable e) {
                          CustomDialog.dismissDialog();
                      }
                  }));
  </code></pre>
  
  <p>Where is my fault? How can I improve it? How can I faster the insertion operation?</p>