-
Notifications
You must be signed in to change notification settings - Fork 595
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
Infinite List Questions, Memory Usage #217
Comments
Hi @radex, const cols$ = database.collections
.get("table")
.query(Q.where("name", Q.like(sanitizedInput)))
.observeOnlyColumns(["id", "updated_at"]) It should follow the same functionality as const sortedIds$ = cols$.pipe(
map(rows => rows
.sort((a, b) => a[1] - b[1])
.map(r => r[0])
)
) Then we sort these on the basis of the columns in JS, and pass it to the FlatList along with a RenderItem Function which returns a component wrapped using Would this solve the problems of #113 and #15 while still being reactive? |
Hm, is that a hypothesis, or did you verify that indeed individual Model instances take enough RAM to be a real problem? My intuition is that moving from a Model to a tuple of simple types wouldn't save much memory unless you have so many of them that other performance bottlenecks arise first |
Well right now we are storing everything in redux and we can see clear correlation between number of entries and RAM usage.
Like even in the example, you would have all the post bodies in memory when rendering the list of posts. I know an alternative would be to move blobs to different file and save their references, but i think querying what is needed can make things simpler while retaining reactivity. |
@radex It's not only a problem with memory. But also passing huge amount of data over the bridge which cause performance issues. With just selected columns of data we'll reduce this overhead substantially. |
I think it would be much simpler for you in the long term to move blobs to a separate place, since only getting raw column values from Watermelon really dumbs down the framework's capabilities - you no longer have reactive records, just pure data. But I understand you point, and can see how this may be necessary / a good idea in some extreme circumstances. So I very much encourage you to continue developing the #609 PR. I will be happy to do code review and merge it if it's good :) |
@radex Thanks your suggestions, but I afraid the workaround may not quite work for large list in offline first apps. Let say I want to limit the list to only show first 5 records in a large table, and I have the list of records pre-filled with sequential
But now if the user deletes record #3, the same query will just return 4 records:
Unless we run additional raw SQL query to manually shift the I understand supporting (PS: Please point out if i got any concepts wrong) Now we are planning to switch out from Realm, we really love the async nature of 🍉 as oppose to Realm's everything is synchronous which freezes the UI and also their performance of insertion is really terrible (more than 0.5 sec of UI freeze per record insertion) as our database size grows. It renders our app completely unusable during data sync. Our use case requires the database to be able to fetch few records with pagination from a list of > 100K records and able to search from it (may use FTS or roll out own tokenization indexer) without freezing the UI. Please advise what I can help on that feature implementation or suggest workaround to use (Side note: I just realized I have commented on a closed issue #113, so I repost it on a relevant open issue) |
Hi @Kenneth-KT, @radex wanted to ask you what is the cache bursting strategy in 🍉? |
@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.
None. 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 |
Hi @radex , I was planning on asking it on another issue but since you mentioned it, I've been trying WatermelonDB for the past few weeks and currently I don't need the observability for my project, so I've been only using raw SQL queries. I didn't have much luck with JOINing tables with raw SQL queries, so I guess it's not supported, or maybe there was something wrong with the syntax I used, however it's not documented so I'm not sure. Could you clarify if it's possible and if it's not at the moment should I open an issue about it ?
This sounds great, I hope the community can start helping with it. Would it make sense to have it in a different API for it in order not to conflict with the normal API ? Something like mango-queries rxdb has? |
You can do any SQL which results in a list of records. (SQLs that result in a number or a list of numbers or something like that are not supported). You can do JOINs - check out tests for encodeQuery, you can see what built in join queries produce for SQL. Please don't open issues for unimplemented features -- but please do send improvements in pull requests :)
No, I don't like the idea of maintaining two different query syntaxes. I think the current query builder can be extended to add limits and order |
I've just implement sortBy, take, skip query operators (for sqlite only, and definitely without taking observability in mind) at I am planning to create a PR for this branch. @radex What are your thoughts about it |
@Kenneth-KT Freaking amazing! Awesome work. Please do make a PR for that -- it will be much easier for me to review this code and give feedback this way |
@radex It has some flaws currently, the order of objects might get messed up after creating new objects since the
If I need to make it better, I guess what I need to do is to implement reloading change set post-processor which refetches objects from database. But anyway, I will make the PR after I finished testing it all out. |
No, as long as you clearly convey that the API may change or not fully work, e.g. |
Take a look at this PR #622 |
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
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
Where I have only those objects which are on screen in memory (or those which have appeared on screen once)
The text was updated successfully, but these errors were encountered: