Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kn/results skip performance #1391

Merged
merged 5 commits into from
Sep 1, 2023
Merged

kn/results skip performance #1391

merged 5 commits into from
Sep 1, 2023

Conversation

nielsenko
Copy link
Contributor

@nielsenko nielsenko commented Sep 1, 2023

This makes skip a simple integer addition, and defer handle construction as long as possible.

  • Fetch handle in _RealmResultsIterator.current lazily (it may never be called for a given index)
  • Support efficient skip on RealmResults

This came about due to https://www.mongodb.com/community/forums/t/do-relationship-properties-get-populated-during-tolist/242260.

skip is useful if you wan't to do pagination for various reasons, even though realm doesn't require it. In this case to support an existing data access layer previously build on another DB.

Fixes: #1392

Copy link
Member

@nirinchev nirinchev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also implement efficient skip for list as well?

@nielsenko
Copy link
Contributor Author

Should we also implement efficient skip for list as well?

Given that ManagedRealmList implements List using a ListMixin (which now a days is equal to ListBase) it actually already uses an efficient implementation for skip.

  Iterable<E> skip(int count) => SubListIterable<E>(this, count, null);

SubListIterable does the right arithmetics for us.

lib/src/results.dart Outdated Show resolved Hide resolved
@nielsenko nielsenko force-pushed the kn/results-skip-performance branch from ab1c41d to 77012b5 Compare September 1, 2023 12:43
@nielsenko nielsenko merged commit b6ffa26 into main Sep 1, 2023
48 checks passed
@nielsenko nielsenko deleted the kn/results-skip-performance branch September 1, 2023 15:09
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RealmResults.skip is inefficient
3 participants