k-paxian / dart-json-mapper

Serialize / Deserialize Dart Objects to / from JSON
https://pub.dev/packages/dart_json_mapper
Other
399 stars 33 forks source link

Build performance slow and "watch" only updating twice #177

Closed idraper closed 2 years ago

idraper commented 2 years ago

version: 2.1.17

Hello, I have two separate issues, don't know if they are related...

First, I'm wondering what the expected performance is for the build_runner. I am finding that it takes longer than a minute to build every time I save a file in my project - which is pretty unusable. I'd really like to use this package since it solves some key issues for me but having to save, wait >1min after every small change is unworkable. For instance - using with flutter means hot reloading kinda defeats the point. Right now I have ~30 classes (which are quite small) to generate (all in a just couple of files), is this typical? If it's this bad with 30 classes, I'm afraid I won't be able to use this package, since it will only grow :/.

Second, when I run flutter pub run build_runner watch --delete-conflicting-outputs it builds correctly (takes ~1.5 minutes), I make a change (eg change JsonProperty name) and it builds correctly, but the third time (always the third time) it no longer builds. To be clear, builder prints successful and other builder dependencies update correctly, only my *.mapper.g.dart file is not updated (it is not deleted, just doesn't update). When it doesn't run the build time is decreased to a few seconds (eg it is clearly not running). It's as if the build_runner doesn't trigger a build even though the first two edits do trigger properly.

Here is my build.yaml (nothing compicated):

targets:
  $default:
    builders:
      dart_json_mapper:
        generate_for:
          # here should be listed entry point files having 'void main()' function
          - lib/main_development.dart

      # This part is needed to tell original reflectable builder to stay away
      # it overrides default options for reflectable builder to an **empty** set of files
      reflectable:
        generate_for:
          - no/files

I'm sure this isn't enough information, but I'm not sure what else to provide; please let me know what other info would be helpful.

k-paxian commented 2 years ago

The first part could be partially answered by this. The more you have part of in your code the slower build_runner will scan your project 🤷

The second one, as you already noticed, full rebuild is not happening every time. Incremental builds are triggered only when it's necessary to reduce the build times even more. The main change to trigger the build so far is by adding/removing @jsonSerializable annotation. So when you need to re-trigger the build just comment out this annotation, on any class, save the file and then un-comment it back.

idraper commented 2 years ago

#1: hmm, looks like it could be related - hard for me to test since we rely on other builders but definitely looks suspiciously similar. Too bad it looks like it's just the way it is with the reflectable library :/.

#2: 🤦‍♂️ wow, super obvious now that you mention it

Thanks for taking a look