Skip to content

Resolve contradictions about deferred loading between Dart and Flutter #7117

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

Closed
elliette opened this issue May 12, 2022 · 11 comments · Fixed by #10083
Closed

Resolve contradictions about deferred loading between Dart and Flutter #7117

elliette opened this issue May 12, 2022 · 11 comments · Fixed by #10083
Assignees
Labels
dev.libraries Related to Dart or Flutter libraries e2-days Effort: < 5 days fix.refactor Needs near total rewrite or reorganization of content p2-medium Necessary but not urgent concern. Resolve when possible. target.Android Target apps on the Android Platform

Comments

@elliette
Copy link
Member

elliette commented May 12, 2022

Page URL

https://docs.flutter.dev/perf/deferred-components
https://dart.dev/language/libraries#lazily-loading-a-library

Page source

No response

Describe the problem

I'm pretty sure that deferred loading is supported in Flutter when running on web and when running on Android.

However, https://docs.flutter.dev/perf/deferred-components states:

Note: This feature is currently only available on Android, taking advantage of Android and Google Play Stores’ dynamic feature modules to deliver the deferred components packaged as Android modules. Deferred code does not impact other platforms, which continue to build as normal with all deferred components and assets included at initial install time.

And https://dart.dev/language/libraries#lazily-loading-a-library states:

Only dart2js supports deferred loading. Flutter, the Dart VM, and dartdevc don’t support deferred loading. For more information, see issue #33118 and issue #27776.

Expected fix

If deferred loading is supported on both platforms, I would expect both notes to say so. If these are separate features (ie, "deferred loading" is different than "different components") than I would expect that to be better documented. Thanks!

Additional context

No response

@darshankawar darshankawar added st.triage.triage-team Triage team reviewing and categorizing the issue p2-medium Necessary but not urgent concern. Resolve when possible. e2-days Effort: < 5 days d: api docs and removed st.triage.triage-team Triage team reviewing and categorizing the issue labels May 12, 2022
@rekire
Copy link
Contributor

rekire commented Jul 1, 2022

I just run into the same situation that I'm confused about the documentation.

What is the current status?

When you change the documentation, it might me worth to mention how to create that libraries. This is still a mystery for me.

Not sure if helpful, but that documentation is hosted here: https://github.com/dart-lang/site-www/blob/main/src/_guides/language/language-tour.md#lazily-loading-a-library

Based on git blame this part of the documentation was not touched for 3 years!

@MiraMarshall MiraMarshall self-assigned this Aug 3, 2022
@churchianity
Copy link

I still don't understand where the web platform stands in regards to this feature.

It sounds like if you use dart compile js to turn your source into js then it is supported, but how exactly is that integrated into the flutter build process?

@sfshaza2
Copy link
Contributor

@ditman, can you clarify?

@ditman
Copy link
Member

ditman commented Mar 29, 2023

AFAIK deferred loading is supported on the web. It is used extensively in the Gallery app:

I am not an expert on this, but AFAIK there's nothing special needed to do when compiling a Flutter web app: flutter build should generate the production chunks.

@jacobsimionato
Copy link

I ran into the same issue as this bug! Thanks for filing, Elliott!

So how about updating https://dart.dev/language/libraries#lazily-loading-a-library to explain that web and Android both support deferred loading.

And then update https://docs.flutter.dev/perf/deferred-components to explain that Web and Android both support this in Dart, but the setup will be different for each platform.

@atsansone atsansone changed the title Contradictory information about deferred loading in two different pages Resolve contradictions about deferred loading between Dart and Flutter Jun 2, 2023
@atsansone atsansone added dev.libraries Related to Dart or Flutter libraries fix.refactor Needs near total rewrite or reorganization of content target.Android Target apps on the Android Platform ltw-triage labels Jun 2, 2023
@atsansone
Copy link
Contributor

@munificent: Any ideas as to why Dart docs contradict in this case?

@munificent
Copy link

munificent commented Nov 1, 2023

No idea. Deferred loading is mostly a mystery to me. Maybe @lrhn, @eernst, or @leafpetersen would know?

@ditman
Copy link
Member

ditman commented Nov 1, 2023

"why Dart docs contradict"

My bet is that the feature was released, and then we forgot to properly update this bit of documentation :)

@lrhn
Copy link

lrhn commented Nov 1, 2023

I have no idea what the status of deferred loading on the VM is. We should ask the VM people.
@mkustermann

From the language's perspective, deferred loading has no effect on program semantics, other than restricting what you can do with deferred types and constants (can't use than as such), and allowing accesses through the prefix to throw until prefix.loadLibrary has succeeded.
Eagerly loading everything is a valid implementation strategy.
I believe that was what the VM did at some point.

For AOT, deferred loading is a deployment issue, more than a compilation issue. If the runtime doesn't have a compiler, it needs some way to introduce the support for the already compiled accesses to deferred declarations. I guess Flutter has done that.

@mkustermann
Copy link
Member

I have no idea what the status of deferred loading on the VM is. We should ask the VM people.
@mkustermann

AFAIK: The VM supports deferred loading. Our AOT compiler can be told to emit deferred components and our AOT runtime will then ask the embedder (e.g. flutter) to load those deferred components. If the compiler is not instructed to do that the code will be eagerly included in the main app. (@rmacnak-google has implemented this, see also go/dart-aot-deferred-loading).

As mentioned above, Flutter enables actual deferred components only on Android.

So I think this needs a documentation update in https://dart.dev/language/libraries#lazily-loading-a-library

@jarrodcolburn
Copy link
Contributor

IMO, conversation on tickets #8659 and #5165 relevant here.


Also, looking at Dart (not Flutter) site for [Web apps > Deployment > Make your app smaller... ](https://dart.dev/web/deployment#make-your-app-smaller-faster-and-more-reliable) you'll see

Web-deployment-Dart


As @ditman points out Flutter (web) Gallery, where you can see all the .js files generated by being deferred as main.dart_js__###_.part.js (where ### is a number)` in devtools

image

atsansone added a commit that referenced this issue Jan 26, 2024
Update deferred loading language. 

Fixes #7117
Fixes #8659
Fixes #5165

Added @johnpryan due to his point on #5165 and @mkustermann due to his
feedback on #7117.

----

Direct link:
https://flutter-docs-prod--pr10083-fix-7717-yr828aok.web.app/perf/deferred-components
atsansone added a commit to atsansone/website that referenced this issue Feb 15, 2024
atsansone added a commit to atsansone/website that referenced this issue Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev.libraries Related to Dart or Flutter libraries e2-days Effort: < 5 days fix.refactor Needs near total rewrite or reorganization of content p2-medium Necessary but not urgent concern. Resolve when possible. target.Android Target apps on the Android Platform
Projects
None yet
Development

Successfully merging a pull request may close this issue.