Skip to content
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

Blazor specific libraries size-reduction tracking #27668

Closed
1 of 11 tasks
samsp-msft opened this issue Nov 9, 2020 · 7 comments
Closed
1 of 11 tasks

Blazor specific libraries size-reduction tracking #27668

samsp-msft opened this issue Nov 9, 2020 · 7 comments
Assignees
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-linking This issue is related to linking in Blazor task Theme: meeting developer expectations
Milestone

Comments

@samsp-msft
Copy link
Member

samsp-msft commented Nov 9, 2020

Source generators can be used to convert code that does reflection.emit at runtime to source generators which will create code at build time rather than runtime. The generated code can then be analyzed by the illinker or native AOT enabling those scenarios. Blazor doesn't use Reflection.Emit directly (though it may use it via dependency injection libraries). However Blazor does use reflection extensively, in the following areas:

  • Routing (Router.cs, RouteTableFactory.cs), to walk the set of exported assembly types to find those with RouteAttribute
  • Component factory (ComponentFactory.cs), to discover the properties with InjectAttribute, which we later populate via DI
  • Parameter assigmment (ComponentProperties.cs, MemberAssignment.cs, CascadingParameterState.cs, PropertySetter.cs), to find the properties on a type with ParameterAttribute and to write supplied values to them Consider using C#9 Source Generators for implementing SetParametersAsync #29550
  • Layouts (LayoutView.cs, RouteView.cs), to discover the LayoutAttribute on a component
  • Data binding (InputBase.cs), because components declare their bound ValueExpression as an Expression<Func> so that the validation system can match it to a FieldIdentifier
  • Validation (FieldIdentifier.cs, EditContextDataAnnotationsExtensions.cs), to know to convert lambda expressions to FieldIdentifier instances (type+propertyname pairs), and to read values of properties matching FieldIdentifier entries in the EditContext, so it can pass those values to DataAnnotations for validation
  • WebAssembly startup (EntrypointInvoker.cs), to find and invoke the assembly entrypoint method Replace EntryPointInvoker in Blazor WebAssembly with code in the runtime #30600
  • Lazy loading (LazyAssemblyLoader.cs), to load assemblies dynamically via Assembly.Load(filenameString)
  • WebAssembly auth (WebAssemblyAuthenticationServiceCollectionExtensions.cs), to generate an "inferred client ID" via Assembly.GetCallingAssembly().GetName().Name
  • <component> tag helper (RootComponentTypeCache.cs, ComponentParametersTypeCache.cs), to look up the type instances corresponding to serialized descriptors of components being rendered into HTML markers
  • BlazorPack (SequenceOfT.cs), to check whether a type is a value type via typeof(T).GetTypeInfo().IsValueType
@Dotnet-GitSync-Bot
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@samsp-msft
Copy link
Member Author

Separated blazor issues from dotnet/runtime#43545

@danmoseley danmoseley transferred this issue from dotnet/runtime Nov 9, 2020
@danmoseley
Copy link
Member

Transferring to asp.net repo - I believe this is essentially all ASP.NET owned? There is a separate story for DI.

cc @mkArtakMSFT - this shows up in https://themesof.net/?q=is:open%20kinds:teui under WASM.

cc @marek-safar

@Pilchie Pilchie added User Story A single user-facing feature. Can be grouped under an epic. Theme: meeting developer expectations labels Nov 9, 2020
@pranavkm pranavkm added the area-blazor Includes: Blazor, Razor Components label Nov 10, 2020
@danmoseley danmoseley changed the title User Story: Source generators to improve trimmability & AOT of blazor apps User Story: Source generators to improve trimmability & AOT of Blazor apps by reducing reflection in Blazor code Nov 10, 2020
@danmoseley
Copy link
Member

making title a bit more specific to improve the tree view.

@charlesroddie
Copy link

Can this be structured so that the core of blazor doesn't depend on reflection/source generators? Source generators are C#-only, and using annotations and DI as an essential part of runtime behaviour is also a C# preference. So these can go together as C# blazor tooling, and F# and the rest of dotnet can develop Blazor apps without using reflection/DI/annotations.

@mkArtakMSFT mkArtakMSFT added this to the Next sprint planning milestone Nov 18, 2020
@ghost
Copy link

ghost commented Nov 18, 2020

Thanks for contacting us.
We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@marek-safar marek-safar added task and removed User Story A single user-facing feature. Can be grouped under an epic. labels Nov 27, 2020
@marek-safar marek-safar changed the title User Story: Source generators to improve trimmability & AOT of Blazor apps by reducing reflection in Blazor code Blazor specific libraries size-reduction tracking Nov 27, 2020
@javiercn javiercn added the feature-blazor-linking This issue is related to linking in Blazor label Apr 20, 2021
@mkArtakMSFT
Copy link
Member

Marked this as cut. We may do some of these items, but can't commit.

@ghost ghost locked as resolved and limited conversation to collaborators Aug 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-linking This issue is related to linking in Blazor task Theme: meeting developer expectations
Projects
None yet
Development

No branches or pull requests

10 participants