Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-153

Grabbing the last few items of a large realm result is orders of magnitude slower than the first few

      Goals

      It is sometimes natural to want the "Top 5" and "Bottom 5" results. As someone coming from other databases, it seemed natural to run a single sorted query, then slice the beginning and end of the list.

      Expected Results

      The retrieval time of both chunks should be fast.

      Actual Results

      In reality, it seems like the end slice is doing a scan through the entire result set. I've worked around this by doing two queries with opposite sorts, but it was surprising behaviour to me.

      Steps to Reproduce

      Reproduction is here: https://github.com/thekevinbrown/realm-js-slow-writes

      Code Sample

      Reproduction is here: https://github.com/thekevinbrown/realm-js-slow-writes

      Version of Realm and Tooling

      • Realm JS SDK Version: 2.29.2
      • Node or React Native: 0.59.10
      • Client OS & Version: Android, Galaxy S9
      • Which debugger for React Native: None, reproduced in release mode.

      Note

      This issue was originally raised as #2499, I'm splitting it out because multiple separate and unconnected issues were discovered in exploring there.

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: