unoplatform / uno

Open-source platform for building cross-platform native Mobile, Web, Desktop and Embedded apps quickly. Create rich, C#/XAML, single-codebase apps from any IDE. Hot Reload included! 90m+ NuGet Downloads!!
https://platform.uno
Apache License 2.0
8.88k stars 719 forks source link

Lazy/Defer Loading of Pages #3839

Closed JohnGalt1717 closed 4 years ago

JohnGalt1717 commented 4 years ago

What would you like to be added:

Add the ability to code split wasm so that pages are automatically split into separate wasm files and the minimum code necessary is always loaded for a given link.

Why is this needed:

Some of the samples are absolutely huge and that's with a small amount of functionality. By splitting code instead of loading it all at once we can get a viable load size on web.

For which Platform:

Anything else we need to know?

Blazor just implemented this in .net 5 I believe. It would be nice to see similar in Uno.

jeromelaban commented 4 years ago

Thanks for the issue!

This feature is not possible at this point for multiple reasons:

The only way to do this at this point is to use the interpreter and download assemblies manually, then execute their code, but it will not be using AOT.

I'm closing this as an external issue, as too many dependents don't support this.

JohnGalt1717 commented 4 years ago

@jeromelaban since Blazor 5 supports this, is it not possible to utilize that code or at least adapt it?

jeromelaban commented 4 years ago

@JohnGalt1717 Uno already supports what blazor supports, by means of Assembly.Load. You can download your assemblies and execute them quite easily.

The part that is not working here is the AOT side of execution.

JohnGalt1717 commented 4 years ago

@jeromelaban OK, then I'm confused. Basically, what at minimum to be viable on the web is needed is the ability to split code by route like how Angular works and now Blazor can do. (still too complex as it should just be part of the routing system)

The reason is that looking at even the samples provided, they load like 40 Mb of stuff and that's a tiny project. If you were to use this for LOB or even for a customer portal after login (to say nothing of public web) that would cause a major loss of users and mobile browser it would become an outright blocker.

Are you saying that that isn't possible to make happen?

jeromelaban commented 4 years ago

@JohnGalt1717 Your original question was mentioning WebAssembly modules, not IL assemblies. It's possible to split code by assembly pretty easily, in a similar way that the Prism modules work. Yet it's not something that will gain much in terms of downloaded size, as assemblies are generally fairly small and compress well.

But all this is using the IL interpreter, so there's a runtime performance cost in using this.

Note that at this point, because of the size/performance tradeoff, .NET for webassembly is best suited WebApps, and not WebSites. The expectations are significantly different in both scenarios.

JohnGalt1717 commented 4 years ago

@jeromelaban Not trying to argue, but on a basic web app (i.e. the same functionality as our ios and android apps) done in typescript lazy loading on angular which also lazy loads shared assemblies that haven't yet been required, the difference on a 3mbps dsl connection is 28 seconds (!!) of load and processing time to first interactivity.

That's just pure source code that is being compressed before being sent. Obviously, web assembly code is more efficient but not that more efficient. I get that the basic runtime is like 2.8 megs. But that means that without images the average page to be loaded without additional nuget packages should be small. But the sample, even after ignoring images is well over 10 megs from what Chrome is reporting.

I.e. if you have 200 navigation points (pages by any other name), you're going to have a HUGE app that has to reload everything, every time you release a new version instead of just the things that have changed. (i.e. angular doesn't recompile all bundles, only those that changed so new versions can have most of the app stay cached)

jeromelaban commented 4 years ago

@JohnGalt1717 That's what I mean by WebApp vs. WebSites. The assumption here is that WebApps have a larger payload to start with (similar to a native app). Yet, I agree, this is not yet the best experience on low-bandwidth networks and this needs to be improved at all levels (WebAssembly, browsers implementations, emscripten, .net and then Uno).

Note that for this dynamic loading scenario, there's no webassembly loaded (aside from the .NET runtime itself), the rest is pure .NET IL.

If you have a large app, you can use Assembly.Load and that works fine.

JohnGalt1717 commented 4 years ago

@jeromelaban Ok, so should this request or a new one but updated to something along the lines of "Navigate Routes should allow lazy loading of assemblies similar to Angular"?

Basically what I'm suggesting is that there should be a standard way to load a route and all dependencies with the navigator so that you can batch them together into something similar to Angular's router.

jeromelaban commented 4 years ago

@JohnGalt1717 That's fair.

As Uno follows the APIs of WinUI, this is not a feature that is provided by WinUI in general in terms of architecture, this is generally the job of opinionated libraries, such as Prism which can perform lazy loading of assemblies based on specific set of conditions (navigation being one).

JohnGalt1717 commented 4 years ago

So last comment and I'll leave it alone:

For UNO to be successful people like me have to be able to see a path to success using it. Right now I don't see that path for several reasons that are basic to essentially all apps today:

  1. SSO via OpenIdConnect has to just work and work across all platforms including web. It works with UWP, iOS and Android right now and nothing else. I understand that this is partially because of the 3rd party library but it would be in the interest of Uno to get this working so that this has a clear user story. This is the defacto solution for SSO and indeed all authentication now-a-days. Most apps don't present their own login and password anymore for security reasons and ONLY trust the IdP for login so this is a major roadblock. (I've mentioned it before and it got punted.)

  2. Load size matters on web. Uno needs to have a good code splitting story. Blazor has the same problem and their current solution for .net 5 is still lacking. This needs to be trivial to implement as a wrapper around the winui navigation stuff that just works and causes assemblies to be loaded on demand when working on web. If it doesn't, then there's a huge problem because of slow load times, even for Web APPS because users won't accept 20-30 second loading screens nor should they. Flutter is also in the process of solving this. Angular already has and does so amazingly well. Uno needs to make it that simple. At the very least there needs to be a clear sample that outlines how this works with Prism and shows people how to hack it together now, but honestly this just needs to be part of Uno and just work without having to do much because all of your competitors do it or are about to, and Uno as it stands right now isn't viable for web.

  3. For us, Video playback that works properly with DRM (all 4 flavors), captions, fullscreen, and speed controls is a big deal and Xamarin still has a horrible experience for this. UWP has an excellent experience. So for us to be able to use this successfully we'd need to see a good cross platform video/audio player that actually works with all environments. This goes to my nuget package comments where these need to be incremental like flutter plugins where a plugin library can have a subset of supported environments and then be extended to others by other people. This is doable right now in .net, it just needs to have a root library that these nuget packages setup with interfaces that do the work. I'd strongly suggest that the Uno and Xamarin/Maui team work on this to have a clear way of doing packages that can be extended for multiple platforms. Video would be an excellent use case to prove it out and is a glaring hole in Xamarin so would be win for all involved to create a complete package that just works and has other packages for other platforms.

I know you're at the whim of people within Microsoft, but hopefully you can get their attention to the fact that because of Flutter it is no longer good enough to have one tool for web and another for apps and they need to start designing libraries so that they work across all 5 platforms day one with all of the vagaries thereof handled intelligently.

We'd MUCH rather be using .NET and UNO looks to be the most promising because Microsoft hasn't come out with a clear 5 platform message, but as it stands right now, there's just too many gaps for us to use it viably. And those gaps are not easy to fill. We were able to fix Flutter's gaps for video, video capture, and SSO pretty easily by extending existing libraries and contributing web for them using the platform interface system. That isn't viable for us here because of lack of guidance and planning. And of course code splitting we know for a fact that the Flutter team is working on it, has a full plan and will have it by the time we release. We don't have any real plan from any of the .NET stacks for the same. It's frustrating to see a third party such as yourselves have to fill this void that Microsoft seems intent on ignoring and you're not even getting the support you need to make it successful. I hope that you can work around the roadblocks and make this thing fly.

francoistanguay commented 4 years ago

So last comment and I'll leave it alone:

Thanks for taking the time to provide this feedback, it`s extremely valuable and extremely appreciated

  1. SSO via OpenIdConnect has to just work and work across all platforms including web. It works with UWP, iOS and Android right now and nothing else. I understand that this is partially because of the 3rd party library but it would be in the interest of Uno to get this working so that this has a clear user story. This is the defacto solution for SSO and indeed all authentication now-a-days. Most apps don't present their own login and password anymore for security reasons and ONLY trust the IdP for login so this is a major roadblock. (I've mentioned it before and it got punted.)

Totally agree. This is something on our short term list. Weve already made sure MSAL.net would work but acknoledge it isnt enough. Uno is first and foremost an UI framework but we do need to make sure all other components integrate smoothly. It`s probably just a matter of guidance but we still need to provide it.

  1. Load size matters on web. Uno needs to have a good code splitting story. Blazor has the same problem and their current solution for .net 5 is still lacking. This needs to be trivial to implement as a wrapper around the winui navigation stuff that just works and causes assemblies to be loaded on demand when working on web. If it doesn't, then there's a huge problem because of slow load times, even for Web APPS because users won't accept 20-30 second loading screens nor should they. Flutter is also in the process of solving this. Angular already has and does so amazingly well. Uno needs to make it that simple. At the very least there needs to be a clear sample that outlines how this works with Prism and shows people how to hack it together now, but honestly this just needs to be part of Uno and just work without having to do much because all of your competitors do it or are about to, and Uno as it stands right now isn't viable for web.

It is my understanding that having AOT+Dynamic Loading is a Mono/WebAssembly/Emscripten limitation for now, not an Uno one. We've been at the bleeding edge on the mono bits, having our own fork and all. As soon as something is possible, we'll definitely want to enable this. Could still rely on interpreter mode + Assembly.Load and agree there that some guidance would be useful, but it is supported, we use it in our Roslyn+SQLite+EF Core sample.

It is also my understanding that regardeless of the package size, bits will get cached. A friendly reminder that we see Uno as an ideal candidate to build Web Apps on top of assembly, not web sites. This means that it should be targeting use cases where Web "apps" are used frequently, in order to leverage the cache.

  1. For us, Video playback that works properly with DRM (all 4 flavors), captions, fullscreen, and speed controls is a big deal and Xamarin still has a horrible experience for this. UWP has an excellent experience. So for us to be able to use this successfully we'd need to see a good cross platform video/audio player that actually works with all environments. This goes to my nuget package comments where these need to be incremental like flutter plugins where a plugin library can have a subset of supported environments and then be extended to others by other people. This is doable right now in .net, it just needs to have a root library that these nuget packages setup with interfaces that do the work. I'd strongly suggest that the Uno and Xamarin/Maui team work on this to have a clear way of doing packages that can be extended for multiple platforms. Video would be an excellent use case to prove it out and is a glaring hole in Xamarin so would be win for all involved to create a complete package that just works and has other packages for other platforms.

no's promise is that we ultimately offer a Universal UI framework on top of native apps. This means that if something isn't offered by Uno, you can still write platform-specific code for this specific use case (DRM Video playback is an excellent example) and still benefit from having everything else look, behave and feel the same on all platforms. We have priorities where we're getting traction and Line-Of-Business scenarios, with richer UI controls (DataGrid, Calenda, TreeView, ...) is where we'll most probably invest in the short term.

I know you're at the whim of people within Microsoft, but hopefully you can get their attention to the fact that because of Flutter it is no longer good enough to have one tool for web and another for apps and they need to start designing libraries so that they work across all 5 platforms day one with all of the vagaries thereof handled intelligently.

We'd MUCH rather be using .NET and UNO looks to be the most promising because Microsoft hasn't come out with a clear 5 platform message, but as it stands right now, there's just too many gaps for us to use it viably. And those gaps are not easy to fill. We were able to fix Flutter's gaps for video, video capture, and SSO pretty easily by extending existing libraries and contributing web for them using the platform interface system. That isn't viable for us here because of lack of guidance and planning. And of course code splitting we know for a fact that the Flutter team is working on it, has a full plan and will have it by the time we release. We don't have any real plan from any of the .NET stacks for the same. It's frustrating to see a third party such as yourselves have to fill this void that Microsoft seems intent on ignoring and you're not even getting the support you need to make it successful. I hope that you can work around the roadblocks and make this thing fly.

Finally, we share your vision for a universal platform and Flutter is clearly "who we're after" and who we benchmark against.

We hope that you'll keep the feedback coming!

sasakrsmanovic commented 4 years ago

@JohnGalt1717

In addition to what Francois said re : SSO via OpenIdConnect .

In my opinion (and some will disagree) this is a more enterprise-level feature that is reasonably high on our priority list. That said, what would help to fast-track this enterprise feature is to have an enterprise company fund it, or co-fund its development. We have enterprise support agreements in place for this very scenario. Of course, the alternative is always to help Uno by contributing this piece of code to the base. We understand that this kind of project is not fit for everyone which is why we offer these kinds of arrangements. You can see more details at https://platform.uno/support/

Sasha Krsmanovic CMO, Uno Platform

Uno Platform
Uno Platform Support
Pixel-Perfect Multi-Platform Applications with C# and WinUI for Windows, WebAssembly, iOS, macOS, Android and Linux