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

Very slow deletion, multiple objects

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None

      What happened?

      I am playing around realm and trying to delete 100k items at once.

      It takes for me around 20-25 seconds for that write to execute

      Maybe my filtering is pretty bad. I followed this syntax: https://stackoverflow.com/questions/70905369/what-is-the-correct-syntax-to-write-a-filter-query-in-realm-net-using-the-in

      Repro steps

      Create a simple poco class that has PrimaryKey Guid

      Create 100k instances and add to the realm.

      Select all the ids and filter the realm on the ids.
      Delete range with the result.

      Expected result: sqllite does it in around 3-4 seconds
      Actual result: 20-25 seconds

      Version

      11.7.0

      What Atlas Services are you using?

      Local Database only

      What type of application is this?

      Console/Server

      Client OS and version

      windows 10 19045

      Code snippets

      public partial class MyObject : IRealmObject
      {
      [PrimaryKey] public Guid Id { get; set; }
      }
      
      Delete(Guid[] ids)
      {
                  using Realm realm = Realm.GetInstance(_configuration);
          var realmDelete = new Stopwatch();
          realmDelete.Start();
      
          var firstId = ids[0].ToString();
      
          var sb= new StringBuilder();
          sb.Append($"Id == uuid({firstId})");
          for (int i = 1; i < ids.Length; i++)
          {
              sb.Append(" OR ");
              sb.Append("Id == uuid(");
              sb.Append(ids[i]);
              sb.Append(")");
          }
          realm.Write(() =>
          {
              var toDelete = realm.All<MyObject>().Filter(sb.ToString());
              realm.RemoveRange(toDelete);
          });
      
          realmDelete.Stop();
          Console.WriteLine($"realm deleted. Elapsed time: {realmDelete.ElapsedMilliseconds} ms"); // i get like 20000ms here
      }
      

      Stacktrace of the exception/crash you're getting

      ```shell

      
      ### Relevant log output
      
      ```shell
      -
      

            Assignee:
            james.stone@mongodb.com James Stone
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: