dart-lang / build

A build system for Dart written in Dart
https://pub.dev/packages/build
BSD 3-Clause "New" or "Revised" License
791 stars 210 forks source link

Use a fine-grained list of imported files #3352

Closed jodinathan closed 2 years ago

jodinathan commented 2 years ago

From what I understand, the build system reads the import section of files and watch all files without checking for unused export clauses and even direct unused imports. It will watch that file regardless of the real usage.

This is very bad for web builds. For example, you use only one tiny component from AngularComponents by importing 'angular_components/angular_components.dart' and if anything changes (related to the used component or not) in the AngularComponents lib, a very big and slow build process will happen.

Is it possible to have a fine-grained list of imports by a file and make the build system use that instead?

it could be optional to not have breaking changes if necessary

jakemac53 commented 2 years ago

From any given analyzer element, you can access its Library, and anything contained in that library. Thus, just importing a library gives the code generator full access to that library and all its transitive imports as well.

So no, we can't feasibly do this, even though it is indeed a major source of slowness in builds (in particular for large projects). In order to do finer grained invalidation we would somehow have to track exactly which elements you visited, and what libraries those elements came from, as well as what other libraries were used to compute those elements (inference may be involved etc).

I could imagine doing that tracking, but we don't have the resources to put into it, and there would be a large ongoing maintenance burden. It would also likely be a large source of bugs.