question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Infinite List Questions, Memory Usage

See original GitHub issue

Hi WatermelonDB developers. Wanted to ask about WatermelonDB usage with an infinite list. I understand that WatermelonDB is lazy first, would I be able to lazily load results of a query until the items are on screen. Wondering if watermelon DB supports something like this using RxJS

$items = $scrollPositionStream.switchMap(postion => runQueryForPosition(position))

Where I have only those objects which are on screen in memory (or those which have appeared on screen once)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:17 (15 by maintainers)

github_iconTop GitHub Comments

4reactions
radexcommented, Feb 4, 2020

@Kenneth-KT You’re right, my suggested workaround has real flaws, which depending on the exact use case may be fatal. To be clear: I’m not against adding SQL-level limiting/ordering to WatermelonDB, I just don’t need it for my use cases, so I’m not going to drive the implementation of it. But if this is key to you, I would highly encourage you to consider contributing those, even in a limited form. I can offer guidance. And yes, @azizhk’s PR is another useful workaround for large lists. Using raw SQL queries is also a great option, if you have a good way to know when to trigger re-fetch. Yes, records fetched using SQL are still 🍉 objects and you can observe them normally.

@azizhk

wanted to ask you what is the cache bursting strategy in 🍉?

None. Observable objects are cached on Query, Relation, but only for as long as they’re observed. And Collection has a cache of { id : Record } objects. Once object with given ID is fetched, it’s going to stay there forever.

My initial plan was to implement a two-level cache, keeping Records in a Map for the first X (100? 200?) records, and then move oldest records to a WeakMap, so that they’re cached only as long as some piece of the app actually keeps a reference to it. If memory usage is important to your app, try contributing this improvement - it may help a lot if you’re dealing with a lot of Records

1reaction
radexcommented, Feb 13, 2020

Do you think that complete handling is necessary for a PR to be accepted?

No, as long as you clearly convey that the API may change or not fully work, e.g. Q.experimentalSortBy().

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to limit memory usage of a lis… | Apple Developer Forums
Basically, I want to display an list of images with an infinite scroll but I want to keep the memory usage reasonable. I...
Read more >
Flutter infinite/long list - memory issue and stack overflow error
I wrote some sample code for a related question about paginated scrolling, which you could check out. I didn't implement cache invalidation ...
Read more >
ulimit not limiting memory usage - Super User
@Gilles: I've tried putting additional constrains on "max memory size", "virtual memory", "core file size", "data seg size", basically everything I can see...
Read more >
Memory usage - Advanced R. - Hadley Wickham
This doubly-linked list makes it easy for internal R code to loop through every object in memory. A pointer to the attributes (8...
Read more >
How is the memory used increasing by using an infinite loop?
A plain infinite loop consumes CPU cycles, not increasing amounts of memory. If you have a process with an infinite loop, and its...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found