43

I want to use ngxs for state management in my Angular 6 application.

But I am not sure if it is mature for big projects.

I can not find any articles about Difference in performance between ngrx and ngxs. Can someone provide some info about it?

Performance metrics: Getting a large number of items form the store and writing back into the store.

2
  • 2
    I bet if you had an Angular application that was running slowly, and you changed which library you were using it would still be running slowly.
    – Reactgular
    Commented Jun 5, 2018 at 16:21
  • 1
    Performance as in what? You need to be more specific.
    – bc1105
    Commented Jun 5, 2018 at 20:51

3 Answers 3

61

Here is good answer from Reddit (Angular2+ community). It's from a developer who tested both and switched to NGXS.

I would like to share my experience. We have a medium-large enterprise app. We started with NGRX, but it quickly became clear that

NGRX code is much difficult to understand and write to teammates.

NGRX is boilerplate hell. You spend lot of time with it.

The concept of "Effects" is good, but it just adds extra layers of complexity which could be simplified.

Developer Experience (DX) was horrifying.

Then we switched to NGXS.

It has minimum boilerplate. You jump right into "action" :D.

We were delighted by its DX.

It is much easier to understand for teammates and everybody was suddenly productive.

There are some tradeoffs like server calls are in reducers, but it made sense to use after a while.

PLUGINS! There are loads of plugins from logging to forms handling (Awesome thing ever).

12

From what I'm experiencing, NGXS is way simpler to write and it's easier to work with lazy loaded states. It has such a simple syntax, it's OOP, instead of Redux FP paradigm. Decorate your actions and selectors, subscribe to memoized states, catch dispatched actions anywhere, etc.

However, I found a pitfall when it comes to the storage plugin which is essentially for offline first applications. It uses sync local storage which has a limit of 5MB and will stall the UI when it needs to write big data to storage. However you could write a custom storage solution on top of the plugin. It's scalable, extensible, you can inject the util classes in a breeze, the documentation is as simple as it can be.

9

I recently had a problem with NGRX, since I had to dispatch two actions, but the second depended on the success of the first, the problem was that the Reducers run asynchronously, and the second action ended without the first one having finished, try to solve it with an Effects , but even there the same thing happened. With NGXS I could solve it since the Dispacher returns an observable at the end of the action.

In general NGXS has worked very well, and the performance is very similar, I had to update a lot of data in an architecture with several nested levels, and there does not seem to be a difference in the update time.

2
  • 5
    The issue you faced with ngrx is not like anything I have come across, I have been using it for a long time, I am sure if you could have posted your issue, you would have found a solution. I have used ngxs as well in another project, I think ngxs's main difference is the plugins and the fact that there is no effects in ngxs. By using Immer and unionize we can make the boiler plate in both redued a lot. so in genernal it is just preference Commented Aug 6, 2019 at 20:55
  • There are effects in ngrs with actions$: Actions just like ngrx. Though I still struggle to see how ngrs less code now with the new ngrx syntax.
    – evanjmg
    Commented Jun 1, 2020 at 12:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.