Uploaded image for project: 'Realm .NET SDK'
  1. Realm .NET SDK
  2. RNET-711

[Bug]: Huge performance drop on update writes Iphone X / Iphone 12

      What happened?

      Background: We are currently using Realm 3.3.0 and from time to time we are measuring times of db operations (inserts, reads, updates, deletes) in several devices both on iOS and Android platforms. The overall conclusion is that Realm has performance degradation on reads and updates operations but in general inserts and delete op are faster. I've compared Realm 3.3.0 against several versions 5.1.2, 10.1.2 and 10.10.0 Performance degradation is main reason why we don't update Realm version, because it's significant especially on older devices.

      On version 10.8.0 there is huge performance drop on updates in newer apple devices like iphone X / iphone 12 on updates with many transactions. On version 10.7.1 my test case on iphone X took 200ms and 10.8.0 over 11000ms, thats over 50-times slower. The same problem is with delete operations with many transactions.
      On Iphone 6+ update in version 3.3.0 took 3800ms and in version 10.10.0 8000ms which is 2 times slower, but still faster than on new iphones

      Repro steps

      My test case is:

      1. create db
      2. insert 1000 objects to db
      3. measure 500 updates, (each update is in separate transaction, this way I simulate actual usage of an app by user)
      4. delete db

      I perform the test 15 times and only step 3 is measured.

      Version

      Mono 6.12.0.93 / Xamarin.iOS 15.0.0.6

      What SDK flavour are you using?

      Local Database only

      What type of application is this?

      Xamarin

      Client OS and version

      iphone X (15.2) / iphone 12 (15.4)

      Code snippets

      My data structure is simple:

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      public class Publication : RealmObject, IPublication
      {
          [PrimaryKey]
          public string Id { get; set; }
      
          public string Title { get; set; }
      
          public string CoverUrl { get; set; }
      
          public int Version { get; set; }
      
          [Indexed]
          public int RemoteId { get; set; }
      
          public bool HasCover => string.IsNullOrEmpty(CoverUrl) == false;
      
          public int DownloadPercentage { get; set; }
      
          public string SomeDescription { get; set; }
      
          [Backlink(nameof(PublicationCollection.Publications))]
          public IQueryable<PublicationCollection> Collections { get; }
      }
      
      public class PublicationCollection : RealmObject, IPublicationCollection
      {
          [PrimaryKey]
          public string Id { get; set; }
      
          public string Name { get; set; }
      
          [Indexed]
          public int RemoteId { get; set; }
      
          public IList<Publication> Publications { get; }
      
          public int PublicationsCount => Publications.Count;
      
          public string CoverUrl => Publications.FirstOrDefault(x => x.CoverUrl != null)?.CoverUrl;
      
          public bool HasCover => CoverUrl != null;
      }
      

      Code which is measured in this case:

      Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      public override int UpdatePublicationsInManyTransactions()
      {
          var total = 0;
          var publications = _realm.All<Publication>().Where(x => x.Version == 1).ToList();
          foreach (var publication in publications)
          {
              _realm.Write(() =>
              {
                  publication.Version = 2;
              });
              total++;
          }
      
          return total;
      }
      

      Stacktrace of the exception/crash you're getting

      No response

      Relevant log output

      No response

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: