Performance regression in query (nativeSize and nativeGetRow)
See original GitHub issueGoal
What do you want to achieve?
Upgrade Realm to latest and retain performance
Expected Results
No performance drop
Actual Results
My query which looks like this became slow when updating from 1.2.0 -> 4.0.0-BETA3-SNAPSHOT.
Date startDate = DateUtils.setToMidnight(date);
Date endDate = DateUtils.setToEndOfDay(startDate);
RealmResults<Schedule> schedules = query(realm)
.beginGroup()
.beginGroup()
.lessThan(ScheduleFields.START_TIME, endDate)
.greaterThanOrEqualTo(ScheduleFields.START_TIME, startDate)
.endGroup()
.or()
.beginGroup()
.greaterThanOrEqualTo(ScheduleFields.END_TIME, startDate)
.lessThan(ScheduleFields.START_TIME, endDate)
.endGroup()
.endGroup()
.lessThanOrEqualTo(ScheduleFields.START_TIME, date)
.equalTo(ScheduleFields.CHANNEL_ID, channel.getId())
.findAllSorted(ScheduleFields.START_TIME);
if(!schedules.isEmpty()) {
return schedules.get(schedules.size() - 1);
} else {
return null;
}
With a schema that looks like this
public class Schedule
extends RealmObject {
@PrimaryKey
private long id;
private String title;
@Index
private String titleLowerCase;
private long categoryId;
private String category;
@Index
private Date startTime;
@Index
private Date endTime;
private int duration;
private String ageLimit;
private long programId;
private String episodeId;
@Index
private long channelId;
private Channel channel;
private RealmList<TVGroup> tvGroups;
The query was then reduced to
Schedule schedule = query(realm)
.lessThanOrEqualTo(ScheduleFields.START_TIME, date)
.equalTo(ScheduleFields.CHANNEL_ID, channel.getId())
.findAllSorted(ScheduleFields.START_TIME, Sort.DESCENDING)
.first(null); // <-- added this
if(schedule == null) {
return null;
}
long scheduleStartTime = schedule.getStartTime().getTime();
long scheduleEndTime = schedule.getEndTime().getTime();
if((scheduleStartTime < endDate.getTime() && scheduleStartTime >= startDate.getTime())
|| (scheduleEndTime >= startDate.getTime() && scheduleStartTime < endDate.getTime()) ){
return schedule;
}
return null;
But it is still slower in first() than in Realm 2.3.0 (and then slow in Realm 3.0.0)
Version of Realm and tooling
Realm version(s): 1.2.0 -> 4.0.0-BETA3-SNAPSHOT
Realm sync feature enabled: no
Android Studio version: 2.3.3
Which Android version and device: LG Nexus 5X, 8.0.0
Issue Analytics
- State:
- Created 6 years ago
- Comments:16 (16 by maintainers)
Top Results From Across the Web
High-Performance Linear Regression - Partition
specifies how observations in the input data set are logically partitioned into disjoint subsets for model training, validation, and testing.
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 Free
Top 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

I’ll test this asap
Well like, previously it was not lagging super-badly while scrolling, and now it does.
But I’ve been doing some method tracing magic and some query optimization
Which is now faster, but apparently the real culprit is
because I’m getting the last element in the RealmResults.
Apparently this is what’s slower now, but I’m not sure why yet. I’ll get the Realm file out.