Yarikx / reductor

Redux for Android. Predictable state container library for Java/Android
Apache License 2.0
463 stars 27 forks source link

How performant is this library? #39

Closed blundell closed 6 years ago

blundell commented 6 years ago

Have you ran any benchmarking tests? Does the Store have any memory limitations? is getState a plain call or should I call it sparingly in tight loops?

I'm considering an app that will fire off an action every 33 milliseconds, on first attempt it is looking like over time the state monitoring is getting slower and slower

blundell commented 6 years ago

after putting in some crude middleware it looks like each action is roughly 40ns slower than the last:

06-01 19:45:00.172 5075-5075/com.package D/TUT: action null[1527882300171]
06-01 19:45:00.223 5075-5092/com.package D/TUT: action PLAY[48]
06-01 19:45:00.339 5075-5092/com.package D/TUT: action PLAY[111]
06-01 19:45:00.509 5075-5092/com.package D/TUT: action PLAY[166]
06-01 19:45:00.727 5075-5092/com.package D/TUT: action PLAY[211]
06-01 19:45:00.989 5075-5092/com.package D/TUT: action PLAY[260]
...
06-01 19:46:28.775 5075-5092/com.package D/TUT: action PLAY[2776]
06-01 19:46:31.596 5075-5092/com.package D/TUT: action PLAY[2819]
06-01 19:46:34.460 5075-5092/com.package D/TUT: action PLAY[2861]
06-01 19:46:37.367 5075-5092/com.package D/TUT: action PLAY[2906]
06-01 19:46:40.318 5075-5092/com.package D/TUT: action PLAY[2948]

Middleware:

public class MiddlewareLogger implements Middleware<Redux.GameState> {

    long timeOfLastAction = 0;

    @Override
    public Dispatcher create(Store<Redux.GameState> store, Dispatcher nextDispatcher) {
        return action -> {
            long diff = System.currentTimeMillis() - timeOfLastAction;
            Log.d("TUT", "action " + store.getState().stage + "[" + diff + "]");
            nextDispatcher.dispatch(action);
            timeOfLastAction = System.currentTimeMillis();
        };
    }
}

It could be something in my code, but wanted to start the conversation. Plus if you had any ideas of what would slow it down like this?

blundell commented 6 years ago

so I was re-allocating 5 Collections on each Action :-) which meant the first Action hadn't finished by the time the second started. So the problem was mine :-)

Would still like to see benchmarking - so that I wouldn't question it ;-)