Skip to content

Very slow deletion, multiple objects #3566

@dkuaf

Description

@dkuaf

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

-

Relevant log output

-

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions