Skip to content

Refactor: split BuildAssetUriResolver into AnalysisDriverModel andd AnalysisDriverModelUriResolver. #3813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

davidmorgan
Copy link
Contributor

@davidmorgan davidmorgan commented Feb 1, 2025

For #3811

BuildAssetUriResolver is critical to performance scalability, it's where the import graph is walked and turned into lists of inputs on each BuildStep.

It's very complicated :)

So my plan is to create a new implementation alongside the existing one to work on, and to increase test coverage; I have a "simplest possible implementation" ready in the next PR.

Before then, there is an improvement possible here. This PR splits one thing BuildAssetUriResolver does out, and introduce an interface AnalysisDriverModel for the part I want to re-implement.

AnalysisDriverModel is build_runner's state related to build steps that use analysis, including an in-memory filesystem for use by the analyzer.

UriResolver is the analyzer's view of that state.

Copy link

github-actions bot commented Feb 1, 2025

Package publishing

Package Version Status Publish tag (post-merge)
package:build 2.4.2 already published at pub.dev
package:build_config 1.1.2 already published at pub.dev
package:build_daemon 4.0.3 already published at pub.dev
package:build_modules 5.0.11 already published at pub.dev
package:build_resolvers 2.4.4-wip WIP (no publish necessary)
package:build_runner 2.4.15-wip WIP (no publish necessary)
package:build_runner_core 8.0.1-dev ready to publish build_runner_core-v8.0.1-dev
package:build_test 2.2.4-wip WIP (no publish necessary)
package:build_web_compilers 4.1.1 already published at pub.dev
package:scratch_space 1.0.3-wip WIP (no publish necessary)

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

Copy link

github-actions bot commented Feb 1, 2025

PR Health

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

…d `AnalysisDriverModelUriResolver`.

`AnalysisDriverModel` is `build_runner`'s state related to build steps that use analysis, including an in-memory filesystem for use by the analyzer.

`UriResolver` is the analyzer's view of that state.
@davidmorgan davidmorgan force-pushed the split-analysis-driver-model branch from 8829523 to 974ee94 Compare February 3, 2025 08:28

@override
Uri pathToUri(String path) {
var pathSegments = p.posix.split(path);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that this is just copied from the other file but just reading this I have no idea why it should be posix? And why is it strings at all?
I'm not saying change it now (you probably shouldn't with this being splitting stuff out) - just noting it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UriResolver is an interface owned by the analyzer that abstracts over a filesystem, it gives it a way to turn URIs into source+paths and paths into URIs.

This class is the view build_runner gives the analyzer of the files it wants to be analyzer.

The paths can be anything as long as they map 1:1 to URIs, so the exact path format is an implementation detail here.

Expanded the class comment to mention some of this:

/// A [UriResolver] on top of [AnalysisDriverModel]'s in-memory filesystem
///
/// This is the analyzer's view of the current build: the files that
/// build_runner wants the analyzer to analyze.
///
/// The in-memory filesystem uses POSIX-style paths with package:foo/bar' /// mapping to /foo/bar`.

if (pathSegments[2] == 'lib') {
return Uri(
scheme: 'package',
pathSegments: [packageName].followedBy(pathSegments.skip(3)),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again I realize this is just copied from other places, so you don't have to change it here.
I'll just say that we, at least in my opinion, are not doing ourselves any favors by using followedBy and skip. We're creating a list and two iterables.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

The analyzer only calls this O(N) times, where N is the number of files; so that won't matter until we've fixed the O(N^2) behaviour. I look forward to getting to that point ;)

Copy link
Contributor Author

@davidmorgan davidmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.


@override
Uri pathToUri(String path) {
var pathSegments = p.posix.split(path);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UriResolver is an interface owned by the analyzer that abstracts over a filesystem, it gives it a way to turn URIs into source+paths and paths into URIs.

This class is the view build_runner gives the analyzer of the files it wants to be analyzer.

The paths can be anything as long as they map 1:1 to URIs, so the exact path format is an implementation detail here.

Expanded the class comment to mention some of this:

/// A [UriResolver] on top of [AnalysisDriverModel]'s in-memory filesystem
///
/// This is the analyzer's view of the current build: the files that
/// build_runner wants the analyzer to analyze.
///
/// The in-memory filesystem uses POSIX-style paths with package:foo/bar' /// mapping to /foo/bar`.

if (pathSegments[2] == 'lib') {
return Uri(
scheme: 'package',
pathSegments: [packageName].followedBy(pathSegments.skip(3)),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

The analyzer only calls this O(N) times, where N is the number of files; so that won't matter until we've fixed the O(N^2) behaviour. I look forward to getting to that point ;)

@davidmorgan davidmorgan merged commit 72b4f5b into dart-lang:master Feb 3, 2025
19 checks passed
@davidmorgan davidmorgan deleted the split-analysis-driver-model branch February 3, 2025 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants