Iterating live result during update (write) is slow
See original GitHub issueProblem
Perfoming the following operations:
Given a dataset of 1000 elements, update matching string with a new string
Takes a ridiculously huge amount time
And the time complexity grows dramatically when increasing the dataset to 10 000 elements
Code snippet
override suspend fun update(param: String, objectToInsert: NewsReportDto) {
realm.query<NewsReportDto>("title == $0", param)
.find()
.forEach { oldNewsReportDto ->
realm.write {
findLatest(oldNewsReportDto)?.apply {
title = objectToInsert.title
description = objectToInsert.description
}
}
}
}
Link to this update method source code Link to the data generator
Performance result
Let me know if i’m doing something wrong, the corresponding update query for Room
"UPDATE newsReport " +
"SET title = :newTitle," +
"description = :newDescription " +
"WHERE title = :title"
takes very little time for example, 20 miliseconds for 1k elements, and 20 miliseconds for 10k elements
Issue Analytics
- State:
- Created a year ago
- Comments:12 (12 by maintainers)
Top Results From Across the Web
Python is slow when iterating over a large list - Stack Overflow
It's probably slow because you load all result in memory first and performing the iteration over a list. Try iterating the cursor instead....
Read more >Gotcha: Entity Framework gets slow in long Iteration Loops
There are a few simple solutions to this problem: Recreate the dbContext/Business object inside of the loop for each iteration. Turn off change...
Read more >Apply for each is very slow - Power Platform Community
Hello, I am using Apply for Each to loop through the records and some conditions in LOOP. My observation is that the Flow...
Read more >Why is iterating over a dictionary slow in Python?
Dictionaries are mutable, and take up more memory than arrays or (named) tuples (when organized efficiently, not duplicating type information).
Read more >Edit Live Photos on iPhone - Apple Support
In the Photos app , you can edit Live Photos, change the key photo, and add fun effects like Bounce and Loop. Edit...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@konnovdev I have been digging a bit and what happens is that the underlying query is most likely re-run when you update the objects, so for now the best thing is probably to iterate the stable result from the frozen
realm.query
. I will have to dig a bit further to understand the details and, if the hypothesis is right, the options of providing a stable results for these use cases.Closing this issue as the various root causes of the lower speed has been explained, but created #914 to enhance the API to provide a stable result for fast and predictable iteration.