Git Product home page Git Product logo

Comments (7)

simolus3 avatar simolus3 commented on September 26, 2024

How many messages are there? Is there an index on the room or on messages.originalId (there should be one if you're using foreign key constraints and have the foreign key pragma enabled)?

How are you opening the database, are you using NativeDatabase.createInBackground?

from drift.

lucasjinreal avatar lucasjinreal commented on September 26, 2024

@simolus3 The laggy I didn't occured previous or not very severe, but recently, when I did something :

I using RxList to contains mssages (with GetX), then for every get have messages.bindStream() operation

Is that possible the issue to cause laggy? It looks like will subscribe streams again and again.

Also, the messages here are 32 max for one batch, and maybe 64 for 2 batch, not too much.

from drift.

simolus3 avatar simolus3 commented on September 26, 2024

then for every get have messages.bindStream() operation

I wasn't aware of RxList before, which package is providing messages.bindStream() or what is that doing?

It looks like will subscribe streams again and again.

Drift is kind of optimized for this since the StreamBuilder widget can cause similar things. If you cancel a subscription and then re-subscribe to it reasonably quickly (one event loop iteration between those, we cancel streams after one Timer.run iteration), the query should not be run again.

from drift.

lucasjinreal avatar lucasjinreal commented on September 26, 2024

It's GetX, widely used, it provides a way to do stream like behavior but simpler, RxList a can a.bindSream to make it use streams return by drift.

Since GetX so widely used, am just wonder the reason, why I using a.bindStream in every time get data from sql and stream to UI got laggy.

One possible reasons is that, when I get data from sql and bindStream, if there is a sql update, and then same time updating UI (since it's stream), it might got some kind of race trace problem

from drift.

simolus3 avatar simolus3 commented on September 26, 2024

Are you calling close() on the rx objects after you don't need them anymore? If you have thousands of "different" streams in drift (different SQL or different parameters), the lag would be unavoidable. It looks like there is no way to unsubscribe from a stream after passing it to bindStream without closing the rx object.

One possible reasons is that, when I get data from sql and bindStream

Why do you call bindStream every time? Do you have a way to use switchMap to combine multiple streams into one if you don't need all of them at once?

from drift.

lucasjinreal avatar lucasjinreal commented on September 26, 2024

@simolus3 I didn't called close() anywhere, since this is a APP lifecycle object to be called.
but the bindStream might called many times eveytime I enter the page, it will be called in initState func.

Where could I close the stream on UI? dispose or somwhere? Does bindStream many times will casued UI laggy?

from drift.

simolus3 avatar simolus3 commented on September 26, 2024

dispose or somwhere? Does bindStream many times will casued UI laggy?

It looks like there is no way to cancel a stream passed to bindStream, so yeah - from a quick look it appears as that method inherently leaks resources.

But let's merge this discussion into #2838, which appears to be about the same problem.

from drift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.