Git Product home page Git Product logo

Comments (10)

gpeal avatar gpeal commented on June 23, 2024

@ATizik Do you have a MvRxStateStore implementation with coroutines? The main reason we used rx is our own familiarity with rx but if coroutines perform better, it would be worth investigating for sure.

cc @BenSchwab @elihart @hellohuanlin

from mavericks.

ATizik avatar ATizik commented on June 23, 2024

@gpeal
I do have something similar in our projects, since you're interested I'll adapt it to MvRx api and share with you

from mavericks.

gpeal avatar gpeal commented on June 23, 2024

@ATizik Would love to see a PR. If you have a good way to benchmark it, that would be great too!

from mavericks.

ATizik avatar ATizik commented on June 23, 2024

@gpeal
Here it is #84
Speed difference was negligible on existing test, maybe I need a heavier state and operations, i'm in the process of writing more comprehensive benchmark. I'll also test a memory consumption later.

from mavericks.

luozejiaqun avatar luozejiaqun commented on June 23, 2024

I still do not understand Why can't simply use the Main Thread to avoid race conditions of setting the state? The stateReducer is just updating the state, why can't put that in the main thread. And if the state changes very frequently, I would prefer to use the LiveData to avoid creating new states.

from mavericks.

ATizik avatar ATizik commented on June 23, 2024

@luozejiaqun
It's better to offload it to the background, there is nothing specific about main thread that's better for avoiding race conditions than any other thread.
I'm not sure how LiveData will help avoid creating new states, we still have to run stateReducer the same amount of times

from mavericks.

luozejiaqun avatar luozejiaqun commented on June 23, 2024

First question, if there is nothing specific about main thread, why don't use the main thread. Since every ViewModel owns a StateStore, using main thread will avoid creating other threads. I'm not familiar with kotlin coroutines, but the fundamental thing is still threads, less threads achieve the same goal, this my rough understanding. If the stateReducer is simple, there is no reason why can't put it in main thread.
Second question, there is not contradiction between State and LiveData, why can't put a property in LiveData and remove it from the State. In this way, the property can be mutable, changes it and sets it to LiveData's value, then done. The fact is there are some properties we can't use in State, such as SparseArray and LongSparseArray. I put these properties in LiveData and that works well for me.

from mavericks.

gpeal avatar gpeal commented on June 23, 2024

@luozejiaqun A fundamental principle of MvRx is that you observe a stream of immutable state. Storing a SparseArray in LiveData actually enables you to write buggy code. If you modify an element in the array, your LiveData won't update. That's why MvRx enforces immutability.

Regarding the background thread, there are performance advantages in keeping it off the main thread but we have implemented it in such a way that there should be no cognitive overhead for the developer. Why not offload things off the main thread if we can?

from mavericks.

luozejiaqun avatar luozejiaqun commented on June 23, 2024

@gpeal I know MvRx enforces immutability, because of the reason, I can't use SparseArray in the State. The MvRx's suggestion is using immutable list, but I don't think that makes sense. Because of performance advantages we use SparseArray, immutable list can't meet that requirements. LiveData maybe buggy, but that's my only choice for now.

Regarding the background thread, I know the performance advantages.But using the main thread and no more new threads also has performance advantages.

from mavericks.

gpeal avatar gpeal commented on June 23, 2024

@luozejiaqun Let's separate that discussion from the coroutines state store

from mavericks.

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.