mobxjs / mobx.dart

MobX for the Dart language. Hassle-free, reactive state-management for your Dart and Flutter apps.
https://mobx.netlify.app
MIT License
2.41k stars 309 forks source link

It take minutes to generate `.g.dart` for Mobx #619

Closed fzyzcjy closed 3 years ago

fzyzcjy commented 3 years ago

Hi thanks for this lib! I find that its code generator is quite slow... For example, I run it and see the following. (sometimes even 2 or 3 minutes):

...
[INFO] 1m 41s elapsed, 2435/2436 actions completed.
[INFO] 1m 42s elapsed, 2454/2470 actions completed.
[INFO] 1m 43s elapsed, 2478/2494 actions completed.
[INFO] 1m 44s elapsed, 2504/2519 actions completed.
[INFO] 1m 45s elapsed, 2566/2573 actions completed.
[INFO] 1m 47s elapsed, 2706/2720 actions completed.
[INFO] 1m 48s elapsed, 2857/2862 actions completed.
[INFO] 1m 49s elapsed, 3044/3045 actions completed.
[INFO] Running build completed, took 1m 49s

[INFO] Caching finalized dependency graph...
[INFO] Caching finalized dependency graph completed, took 873ms

[INFO] Succeeded after 1m 50s with 363 outputs (3286 actions)

And I see it eats 1 core ("100% cpu") during this build. Is there any way to make it faster?

EugenePisotsky commented 3 years ago

Maybe it's a problem of dart's builder. I faced similar problems with other libraries that generate code

fzyzcjy commented 3 years ago

@EugenePisotsky so how do you solve it? thanks

EugenePisotsky commented 3 years ago

@fzyzcjy I didn't. just replaced libraries that require code generation

fzyzcjy commented 3 years ago

@EugenePisotsky Ouch so which lib do you use instead of mobx.dart? IMHO there is no lib with exactly the same behavior...

EugenePisotsky commented 3 years ago

@fzyzcjy GetX borrowed the idea. its state management looks very similar and easy to migrate. but they are not very appreciated by flutter community (accused of being toxic and false advertisement) and it brings too much other unnecessary features as part of the single library, so if it doesn't sound like a problem for you, you can give it a try :)

fzyzcjy commented 3 years ago

@EugenePisotsky Thanks for your reply. However, that seems not a very good choice...

Rudiksz commented 3 years ago

Wow, that's a lot of "actions" , are those all from mobx stores? I have a full app with dozens of data classes and even more controllers that are mobx stores and I'm nowhere near that amount.

2-3 minutes doesn't sound too bad for a large codebase, but I think the issue is actually with build_runner. Sometimes I think it would be easier to just have a yaml file to configure stores and generate Dart code the old fashioned way, using plain string templates and sprintf.

fzyzcjy commented 3 years ago

@Rudiksz Hmm I guess so. I only have json and mobx code generators (and json are often fast)... My dart code is about 30~40k lines with maybe >100 stores (not counted, just guess #store)