request: Optimize melos bootstrap
by Skipping Unchanged Packages Based on Git Commit Hashes
#797
Closed
1 task done
Labels
Is there an existing feature request for this?
Command
melos bootstrap --cache
Description
First of all, this may be a stupid idea. I just want to get your feedback on it.
Problem Statement
In large Flutter monorepos containing a significant number of local packages (e.g, around 300) that depend on each other via path references, running melos bootstrap can be time-consuming. Even with caching mechanisms for third-party dependencies in the .pub_cache folder, the process involves running flutter pub get for each local package, regardless of whether it has changed since the last bootstrap. This results in unnecessary processing time and slows down development workflows.
Proposed Solution
Introduce an optimization in the
melos boostrap
process to skip runningflutter pub get
for packages that havn't changed since the last bootstrap. This can be achieved by:1. Tracking Package Commit Hashes
package_hashes.json
that stores a mapping of each package to its latest Git commit hash.2. Modifying the Bootstrap Process:
melos bootstrap
, for each package:package_hashes.json
flutter pub get
for that packageflutter pub get
package_hashes.json
with the latest commit hashes.Implementation Details
1. Getting the Latest Comit Hash for a Package
Get the last commit for a path that the package is located:
git log -n 1 --pretty=format:%H -- path/to/package
. We may need to expand this solution to catch un-commited changes as well.2. Storing Commit Hashes
The
package_hashes.json
file would have a structure like:This file will be updated whenever
melos bootstrap
is called if the feature enabled. A question arises here: What will happen when we runflutter pub get
manually for a package.Potential Limitations and Some Whys in my Mind
Dependency Changes: If a package depends on another local package that has changed, even if the dependent package's code hasn't changed, will it still require
flutter pub get
?Uncommited Changes
Uncommited changes won't be detected using commit hashes. Can computing checksum of uncommited changes computed along with the last commit changes help here?
Synchronization Issues
Running
melos bootstrap
will make sure to sync thepackages_hashes.json
but there can be other situations that needs to run synchronization. For example, runningflutter pub get
manually.Melos's Diff Option
Do we really need this feature while we have a diff option for bootstrapping?
Reasoning
I believe this feature will be valuable because subsequent melos bootstrap commands currently take about 3 minutes to execute in our monorepo.
Additional context and comments
No response
The text was updated successfully, but these errors were encountered: