realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.78k stars 575 forks source link

would it consume too much memory to sort large data set? #756

Closed chrischjh closed 7 years ago

chrischjh commented 7 years ago

Hi there, is the sorting being done purely in memory? for example if I need to sort 5 million data, would it consume too much memory? thanks

nhachicha commented 7 years ago

Hi @chrischjh the C++ core uses std::sort on B+tree, so roughly speaking it should require ~ 100MB, that's:

I would suggest filtering the query to limit the number of results, before sorting.

chrischjh commented 7 years ago

Hey thanks for the answer, then I think it would not consume the memory of my Node.js process, right? That's exactly what I'm looking for. By the way, I'm using levelUp as my local cache, however the sorting has to be done in node.js process memory, also asked the same question to PouchDB, looks all levelDown db clients work on the similar way.

astigsen commented 7 years ago

With Realm all the query processing (including sorting) happens off-heap (it is entirely managed by the C++ part of the library), so it does not affect node's internal memory use (and is for the same reason not something node has to spend time garbage collecting afterwards).